Android life cycle onActivityResult vs onStop

If activity A starts action B for the result, I have the impression that the onStop method of activity B is called before the onActivityResult activity method. Why is this not so? I just tested it with the static variable set in B.onStop , but when I read it in A.onActivityResult , the variable is up to null.

+6
source share
2 answers

I think what you want to do is call onPause , however you do not want to do too much. Here's what the docs say :

protected void onPause () Added to API level 1

Called as part of the life cycle of an activity when an activity occurs in the background, but has not yet been killed. Analogs onResume ().

When action B starts before activity A, this callback will be called on A. B will not be created until A onPause () is returned, so be sure to do nothing long here.

This callback is mainly used to maintain any constant state of activity being edited, to present the user with "in-place editing" and to make sure that nothing is lost if resources are insufficient to start a new activity without first killing it. It is also a good place to do something like stopping animations and other things that consume a significant amount of CPU, to make the switch as fast as possible, or to close resources that have exclusive access, such as a camera.

+3
source

I think your impression is wrong, onActivityResult is called before onResume and the documentation for onStop in http://developer.android.com/reference/android/app/Activity.html in the table following the activity cycle diagram contains

Called when an action is no longer displayed to the user because another operation has been resumed and covers this one . This can happen either due to the fact that a new activity begins, but also before it happens, or that this object is destroyed.

Thus, onResume in is called before onStop in B is called.

+2
source

All Articles