Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a remote Service send messages to a bound Activity?

I've read the documentation about Bound Services, where it is shown that you can easily communicate through Messages from an Activity to a remote (i.e. not in the same context) Service but is there any way to send messages from the Service to the bound Activity? For example, my activity bounds to a running background service of the same application, sends a message to it and upon the reception of this message the service replies with a message to the activity.. how do I implement this? Can you point me to some documentation that explains this topic?

like image 679
Gianni Costanzi Avatar asked May 11 '12 07:05

Gianni Costanzi


People also ask

How do you communicate between service and activity?

We know how much service are important in Android Application Development. We already know that we can communicate with Service from activity just by using method startService() and passing Intent to the argument in the method, or either we can use bindService() to bind the service to the activity with argument Intent.

Is it possible for a service to communicate with the activity if yes how?

Communication between service and Activity can be done using PendingIntent. For that we can use createPendingResult(). createPendingResult() creates a new PendingIntent object which you can hand to service to use and to send result data back to your activity inside onActivityResult(int, int, Intent) callback.

What is a bound service?

A bound service is the server in a client-server interface. It allows components (such as activities) to bind to the service, send requests, receive responses, and perform interprocess communication (IPC).

How do you create a bound service?

There are three ways of creating bound services: First is by extending the binder class. Second is by using a messenger. Third, is by using AIDL or Android Interface Definition Language.


1 Answers

Found example in the reference documentation at Remote Messenger Service Sample.

like image 119
Gianni Costanzi Avatar answered Sep 16 '22 18:09

Gianni Costanzi