Example of an activity communicating to a service through Messenger.
If you need your service to communicate with remote processes, then you can use a Messenger to provide the interface for your service.
Here's a summary of how to use a Messenger:
- The service implements a Handler that receives a callback for each call from a client.
- The Handler is used to create a Messenger object (which is a reference to the Handler).
- The Messenger creates an IBinder that the service returns to clients from onBind().
- Clients use the IBinder to instantiate the Messenger (that references the service's Handler), which the client uses to send Message objects to the service.
- The service receives each Message in its Handler—specifically, in the handleMessage() method.
See https://developer.android.com/guide/components/bound-services.html#Messenger for more info.