- You can send your “Your Messages” service to your
Messenger
activity so that it responds as soon as the service detects new content (see this section on Android developers’s help / activity about Messenging).
Here are examples for two-way messaging (from service to activity and from activity to service). Quoting a document:
You can see an example of how to provide two-way messaging in MessengerService.java (service) and MessengerServiceActivities.java (client) samples.
Here are the relevant parts.
Inbound handler in action:
class IncomingHandler extends Handler { @Override public void handleMessage(Message msg) { switch (msg.what) { case MessengerService.MSG_SET_VALUE: mCallbackText.setText("Received from service: " + msg.arg1); break; default: super.handleMessage(msg); } } } final Messenger mMessenger = new Messenger(new IncomingHandler());
In a service showing only the relevant parts:
class IncomingHandler extends Handler { @Override public void handleMessage(Message msg) {
- You can also
bind
to your service from your activities and periodically call one of your service methods to check for new content. To do this, if your service is another application, you should use helpl (this is more complicated). If it is in one package, I advise you to use the local service binding much easier
source share