tags:

views:

7

answers:

1

I have 2 Activities that need to communicate with each other: ActivityA and ActivityB

Say that ActivityA opens ActivityB. How do I unicast a message from ActivityB to ActivityA without closing ActivityB?

Here's what I tried:

  1. setResult() - but the intent will be delivered only when ActivityB closes

  2. sendBroadcast() - but this sends the intent to everyone listening to the action. I only want the action to reach ActivityA since it spawned ActivityB. I tried having ActivityA registering a BroadCast receiver, but I cannot target that via Intent's SetComponentName().

  3. startActivity() - this brings up ActivityA, which I don't want

+1  A: 

I have 2 Activities that need to communicate with each other: ActivityA and ActivityB

You think they need to communicate with each other. I'd argue that, other than startActivityForResult()/setResult() pattern, ActivityB should not be communicating with ActivityA. Instead, they should be working through something else (e.g., service) that represents your model.

How do I unicast a message from ActivityB to ActivityA without closing ActivityB?

Use your option #2 and setPackage() to constrain the delivery.

CommonsWare