Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7077085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:22:44+00:00 2026-05-28T06:22:44+00:00

I have a such Service: public MyService extends Service { // … IBinder binder

  • 0

I have a such Service:

public MyService extends Service {

    // ...

    IBinder binder = new MyBinder();

    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    public class MyBinder extends Binder {

        public MyService getService() {
            return MyService.this;
        }
    }

    // ...
}   

In Activity I receive Binder thereby get Service instance, and after that I have access to all its methods. I want to know, is it safe to do like that? Or I should interact with Service only through Binder interface? Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:22:45+00:00Added an answer on May 28, 2026 at 6:22 am

    In Activity I receive Binder thereby get Service instance, and after
    that I have access to all its methods. I want to know, is it safe to
    do like that? Or I should interact with Service only through Binder
    interface?

    The Binder is what gets returned and you simply cast to the Service class you know it to be. The way that you’re doing it IS only using the Binder…

    And the way you’ve done it is typically how it’s done. It’s the “local service” pattern taken directly from the “official” sample found here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/LocalService.html Other ways of calling methods on your Service class are quite hacky (believe me, I’ve tried them before).

    Example:

    private ServiceConnection mConnection = new ServiceConnection() {
            public void onServiceConnected(ComponentName className, IBinder service) {
                // This is called when the connection with the service has been
                // established, giving us the service object we can use to
                // interact with the service.  Because we have bound to a explicit
                // service that we know is running in our own process, we can
                // cast its IBinder to a concrete class and directly access it.
                myService = ((MyService.LocalBinder)service).getService();
    
    
    
            }
    
            public void onServiceDisconnected(ComponentName className) {
                // This is called when the connection with the service has been
                // unexpectedly disconnected -- that is, its process crashed.
                // Because it is running in our same process, we should never
                // see this happen.
    
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a method exposed from a WCF service as such: public GetAllCommentsResponse
I have a web service to get an object, such as public Blah GetBlah(int
I have a Service class such as following: @Transactional @Component(value = userServiceImpl) public class
I have only simple data types in method signature of service (such as int,
Summary A parent can have many children. How do you write a service such
I have a Silverlight 2 application that is consuming a WCF service. As such,
I have such a form: <form id=new-application method=post enctype=multipart/form-data data-remote=true action=/inv/claims?locale=uk accept-charset=UTF-8> <a rel=nofollow
I have a RPC service with the following method: public List<Serializable> myMethod(TransactionCall call) {...}
I have a RESTful WCF service and I've implemented an ErrorHandler such as the
Basically, here's the situation. I have the following: public IService Service { get; set;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.