[ACCEPTED]-Android communication between two services-service

Accepted answer
Score: 17

You have to use BroadcastReceiver to receive 4 intents, and when you want to communicate 3 simply make an Intent with appropriate values.

This 2 way you should be able to make a 2-way communication 1 between any component.

Score: 3

In Android, there is a special way of completing 30 tasks like yours. Look at AIDL (it's not 29 well documented in official docs, but there 28 are some extra sources on the web). This 27 is a way of implementing two-way communication 26 between any components placed in separate 25 processes. In comparison to BroadcastReceivers, using 24 this you'd get direct calls and callbacks, that 23 will be less dirty than relying on something 22 would come from somewhere in BroadcastReceiver.

To 21 reach the needed effect, you'll have to 20 define an interface for a callback and an 19 interface for performing actions (with a 18 callback supplied, or register/unregister 17 methods). Than, after you received some 16 command using the second interface, you 15 should perform the job and post back the 14 result through callback. To reach the asynchronous 13 completion add a key work "oneway" before 12 method signature (return type). To separate 11 in and out params (if you need it), use 10 "in", "out" and "inout" keywords near params.

As 9 it comes to restrictions, only primitives, arrays 8 and parcelables (and parcelable arrays) might 7 be transferred between processes.

To control 6 your callbacks lifecycle and operations 5 atomicity, use RemoteCallbacksList for storing 4 registered callbacks and notifying recipients 3 using the duplicate of your list got from 2 beginBroadcast.

If you have any troubles, you're 1 free to ask here.

More Related questions