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 cl开发者_如何学Cosing ActivityB?
Here's what I tried:
setResult() - but the intent will be delivered only when ActivityB closes
sendBroadcast() - but this sends the intent to everyone listening to the action. I only want the action to reach
ActivityA
since it spawnedActivityB
. I tried having ActivityA registering a BroadCast receiver, but I cannot target that via Intent'sSetComponentName()
.startActivity() - this brings up ActivityA, which I don't want
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.
精彩评论