incremented
incremented

Reputation: 65

Using Messengers and Binders for Inter Process Communication

I am facing the following problem.

My Application needs to communicate between 2 Services, 1 for Network, 1 for rudementary Phoneservices.

Now, I did the following to achieve IPC:

I extended the BinderClass as normal, and return an own Binder in my onBind() method. That works just fine. But now I want to have in addition to that the possibility to send Messages between my Service and my Activity. But here lies the problem. Since I return my own Binder in the onBind() method like this:

@Override
public IBinder onBind(Intent intent){
    Log.d(this.getClass().getName(), "BIND");
    return binderToThisProcess;
}

I can not return an additional Messenger like this:

...
return outMessenger.getBinder();

I mean of course this is obvious cause the return statement allows only one Object to be returned.

My Question is: Is there any way I can append the Messenger onto my own Binder? Or is there a similar way to achieve what I am looking for? Or did I miss something?

Upvotes: 3

Views: 824

Answers (1)

HitOdessit
HitOdessit

Reputation: 7256

The solution seems very obvious for me - just write your own class what extends Binder. You can add any custom fields or methods to your CustomBinder class. Simply instantiate your CustomBinder and return it in onBind() method.

Upvotes: 2

Related Questions