Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an Android service provide two interfaces to communicate with?

I have a service that communicates through AIDL with other services. I want that service to be bound by activities in my application. Can the service define two binders\interfaces? I've tried yo use a messenger for communicating with the activities, overriding "onBind" method so that it returns a different binder according to the intent it gets (one for the other services and one for the activities).

But when the activities (that use the same binder) unbind from the service, I have an error "myService has leaked ServiceConnection ... that was originally bound here", which I believe is about the binder the service use to communicate with the other services.
If a service cant use two interfaces, how can I implement the communication between the activities and that service?

thank you, -Liron

like image 805
lironda Avatar asked Dec 23 '12 16:12

lironda


1 Answers

If by

"overriding "onBind" method so that it returns a different binder according to the intent it gets "

You mean, that you set an extra to your Intent, indicating what to do it won't work. According to the Docs in onBind(Intent):

Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Try to give your intent a custom action and check if that works

like image 143
Rafael T Avatar answered Oct 10 '22 10:10

Rafael T