I am sending a broadCast from App A to app B, app B has a BroadCastReceiver
to handle intent.
Now I do some operation in onReceive
in App B's BroadcastReceiver
and then I want to get result back to App A, so that I can have a callback, and continue operations if result is positive.
Below some code.
inside App B:
public class TripBackupReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
System.out.println("broadcast Received");
// send result back to Caller Activity
}
}
inside App A:
Intent intent = new Intent("a_specified_action_string");
sendBroadcast(intent);
Can anybody have any solution for this problem, please guide me with some suggestions. Thanks!!
Why not just (sort of) send an
Intent
fromTripBackupReceiver
that is received by App A?Something like:
You could receive this
Intent
in aBroadcastReceiver
defines in App A. Or alternatively use theContext.startActivity(Intent)
method to start an activity in App A.You may need to implement
onNewIntent()
if this makes a call to an activity that is already running.Please use signed intents for this, in order to prevent users from hacking into your Intent API.
I was looking for something similar. This helped me tremendously.
Basically, instead of a sendBroadcast(Intent) try using a suitable form of sendOrderedBroadcast() which allows setting a BroadcastReceiver to handle results form a Receiver. A simple example: