I have 2 Android apps - App1 and App2. I have a bound service - ServiceA in App1. Multiple services and activities in App1 bind to ServiceA and call methods on it. Now, I want to send data from ServiceA to a remote service that exists in App2. I will be using the Messenger API to expose the binder object from ServiceA for inter-process-communication.
From what I understand, all the activities and services dependent on ServiceA in App1 will also now need to use the Messenger
API to access the binder. Is this correct?
If yes, is there a way to make changes only to ServiceA so that it can exchange data with the remote service without making changes to it's existing clients?
P.S: The service doesn't need to handle multiple concurrent requests which is one of the main reasons I decided to go with the Messenger
API.
You should be able to provide both a
Messenger
based interface and a direct interface. I've not tested this myself, but you can try this:In
onBind()
you receive anIntent
. This is theIntent
that the client used when callingbindService()
. You can use 2 different ACTIONs (or use "extra"s) in theIntent
so that you can differentiate between the calls from App1's clients and App2's clients. Then just return either aMessenger
basedBinder
or your current implementation, depending on which client has calledonBind()
.Let me know how it goes!