简体   繁体   English

从不同于接收活动的活动返回结果

[英]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. 从第一个应用程序的主要活动中,它调用startActivityForResult()来启动第二个应用程序的主要活动。 I know I can send result through Intent from second app's main activity. 我知道我可以通过Intent从第二个应用的主要活动发送结果。

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. 让我们假设你有三个活动- A在第一个应用程序和BC在第二个应用程序。

I see two possible scenarios: 我看到两种可能的情况:

  1. Chaining the result - A starts for result B starts for result C . 链接的结果- A开始用于结果B开始用于结果C The result from C is delivered to B , B delivers it as a result to A . C的结果传递给BB的结果传递给A
  2. Using Intent s directly - don't start B for result, but use explicit Intent s to return the result to A . 直接使用Intent -不要为结果开始B ,而是使用显式Intent s将结果返回给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. 这意味着您应该将A的启动模式设置为singleTop并使用适当的标志来确保您不会遇到该活动的多个实例。 You can also fire Intent s not directly to A , but to a BroadcastReceiver that will handle them accordingly. 您也可以不将Intent s直接激发到A ,而是激发到BroadcastReceiver ,后者将相应地处理它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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