简体   繁体   中英

Return result from different activity than receiving activity

I have two apps. From the first app main activity it calls startActivityForResult() for launching second app's main activity. I know I can send result through Intent from second app's main activity.

But for some case if second app's main activity launches another activity and it finish the main activity then how I can send result to first app's main activity from second app's another activity?

Let's assume that you have three activities - A in the first app and B and C in the second app.

I see two possible scenarios:

  1. Chaining the result - A starts for result B starts for result C . The result from C is delivered to B , B delivers it as a result to A .
  2. Using Intent s directly - don't start B for result, but use explicit Intent s to return the result to A . This means you should set A 's launch mode to singleTop and use appropriate flags to make sure you won't end up with multiple instances of the activity. You can also fire Intent s not directly to A , but to a BroadcastReceiver that will handle them accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM