Vlad
Vlad

Reputation: 755

2 Services Communicating

I have a service that starts another remote service. when the second service have started, it binds to the first service using IPC, and all works great.

My question is, i would like the first service to be able to talk to the second service as well (right now, only the other way around is implemented). can i somehow do it with the same Binder? or should i bind the first service to the second one? maybe there's a way to make two services talk on the same connection somehow?

All help would be appreciated.

Vlad

Upvotes: 2

Views: 192

Answers (2)

AlbertoAndreotti
AlbertoAndreotti

Reputation: 510

I think that two way communication using the same binder is impossible for services. I have tried a lot, and the problem I found, using the parlance of your own example is that IBinder interfaces retrieved from the second service are always null. I mean, the first service would have bind to the second in order to obtain a valid IBinder to talk to the second service. The limitation is that when the second service calls the first, it cannot pass interfaces to the first service so callbacks(from first to second) can take place. A new independent IBinder connection to the second service needs to be established, instead. Hope somebody can help us with this one.

Alberto.

Upvotes: 1

LuxuryMode
LuxuryMode

Reputation: 33741

If you need the first Service to call methods on the second Service, then you'll need to get a Binder from the second Service. If you just want to communicate, you could use Broadcasts and set up a Receiver in the first Service.

Upvotes: 4

Related Questions