Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onDestroy() while "waiting" for onActivityResult()

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.

like image 219
Thomas Calc Avatar asked Apr 25 '12 15:04

Thomas Calc


People also ask

What is called after onActivityResult?

onActivityResult, called after onResume, The basic reason that when your jump from your activity to another activity without calling finish. Then last activity went in onStop state.

Is onActivityResult called before onCreate?

Android instantiates a new instance of the Activity that will get the result (the one that called startActivityForResult() ) Android calls onCreate() on the new Activity .

What is onDestroy?

onDestroy: The final call you receive before your activity is destroyed.

How do you get a response from an activity in Android?

startActivityForResult(Intent intent,int requestCode) will give the response from second activity to first activity as a result.


1 Answers

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.

like image 59
Alex Lockwood Avatar answered Oct 05 '22 01:10

Alex Lockwood