本文介绍了的onDestroy(),而"等待"对于onActivityResult()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动,一个应用程序:A和B

I have an app with two activities: "A" and "B".

A使用 startActivityForResult()产卵B,即它会等待B。现在,假设B是在前台。 Android系统可能会破坏活动A也没有破坏B? (如果是的话,那么当B已完成,例如用户输入,活动A必须重新创建,并通过Android系统付诸前景一遍,我需要记住和恢复A到其先前的UI状态后。 )

"A" uses startActivityForResult() to spawn "B" i.e. it waits for "B". Now, assume that "B" is in foreground. Can the Android system destroy activity "A" without also destroying "B"? (If yes, then when "B"is finished e.g. after user input, activity "A" must be recreated and put to the foreground again by the Android system, and I need to remember and restore "A" to its earlier UI status.)

请注意,我不是在谈论过程中的的(这是不同的情况:如果一个进程被终止,所有的活动都死亡,的onDestroy()不叫或不保证调用) 。现在的问题是仅仅约的onDestroy()是否可能在等待一个子活动的结果。

Note that I'm not talking about process kill (which is different case: if a process is killed, all activities are killed and onDestroy() is not called or not guaranteed to be called). The question is merely about whether onDestroy() is possible while waiting for the result of a subactivity.

推荐答案

如果活动一个被杀害的时间B结束,这样保证了

If Activity A gets killed by the time B finishes, you are guaranteed that

  1. 系统的将会的重新创建。
  2. 系统的将会的交付结果。
  1. A will be re-created.
  2. A will deliver the result.

在换句话说,A将被重新创建在下次用户访问/需要它,在这一点上任何挂起的结果将交付(从B到A)。

In other words, A will be re-created the next time the user visits/needs it, and at that point any pending results will be delivered (from B to A).

另外请注意,这是为什么结果必须通过一个活动回调整数请求code返回,而不是任意的回调对象。

Also note that this is why results must be returned through a single Activity callback with an integer request code, instead of an arbitrary callback object.

这篇关于的onDestroy(),而"等待"对于onActivityResult()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:19