onDestroy() while “waiting” for onActivityResult()

烂漫一生 提交于 2019-12-18 02:18:31

问题


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

"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.)

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.


回答1:


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

  1. A will be re-created.
  2. A will deliver the result.

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).

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.



来源:https://stackoverflow.com/questions/10319330/ondestroy-while-waiting-for-onactivityresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!