How to establish two-way communication between Activity and Service in different processes?

I am working on establishing a two-way communication between an Activity and a service that runs in another process.

A process request from an Activity is not a big deal. But I want the process to notify Activity of events. The idea behind this is: the service runs regardless of the actual application. It periodically requests a web server. If a new task is detected on the web server, the process should notify you.

I found this thread on AndDev.org, but it doesn't seem to work for me. I fiddled with BroadcastReceiver. I implemented an interface that should notify about activity, but the problem is that the listener is always zero, since the translation from the process is performed through Intent, so the class that extends BroadcastReceiver will be re-created.

How to establish two-way communication? It should be possible. Thanks for any help,

Steff

+7
android android-intent android-activity process service
source share
3 answers

Use BroadcastReceiver or Activity register a callback or listener object so that the Service raises key events. The links above are examples of projects demonstrating each of these technologies.

+4
source share

I think you need to start BroadcastReceiver again your activity with the result in the intent.

Or you can use AIDL about AIDL. Samples also have an example (a few?), How to use AIDL and services. But AIDL can be a big problem for your purpose.

+2
source share

You must use BroadcastReceiver to get intentions, and when you want to communicate, just make an intent with the appropriate values.

Thus, you should be able to make two-way communication between any components.

+2
source share

All Articles