Daniel C
Daniel C

Reputation: 2480

Single service with multiple AIDL interfaces in Android

How can I serve multiple AIDL interfaces from a single Service? The scenario is the following:

                    |---Client_1
          |--AIDL1--|     ...
          |         |---Client_6
MyService |
          |         |---Client_4
          |--AIDL2--|     ...
                    |---Client_9

My idea was to use the intent from the method public IBinder onBind(Intent intent) to somehow find out the type of client application calling and the AIDL in which this client is interested in. Is this possible?

Upvotes: 5

Views: 4143

Answers (1)

HolaMan
HolaMan

Reputation: 391

I also have the same question and write the prototype for testing. Actually it should works by examine the intent and return different binder according to the intent extras.

But after testing, I found the onBind only call once for the first client. After that, system will return the cached binder to later clients who want to bind the service.

Android official document describe

Multiple clients can connect to the service at once. However, the system calls your service's onBind() method to retrieve the IBinder only when the first client binds. The system then delivers the same IBinder to any additional clients that bind, without calling onBind() again.

I still try to find ways but it seems not possible to do that.

Upvotes: 3

Related Questions