Issue
I wonder if onSaveInstance()
, onPause()
and onStop()
are called if I call finish()
or the lifecycle jumps directly to onDestroy()
.
I also would like to know if android.support.v4 library's onRetainNonConfigurationInstance()
is always called or just when the activity is recreated because of a configuration change (can I trust it when the activity is stopped and put on the backstack?)
thanks
Solution
You can pretty much test you frist question your self by adding a log on all those methods. As for you 2nd, onRetainNonConfigurationInstance() is called when its being recreated.
This method is used in ActivityThread class to destory the activity and has these lines of code:
3424try {
3425 r.lastNonConfigurationInstances
3426 = r.activity.retainNonConfigurationInstances();
3427} catch (Exception e) {
3428 if (!mInstrumentation.onException(r.activity, e)) {
activity.retainNonConfigurationInstances(); then will trigger onRetainNonConfigurationInstance()
And also, if you look at the docs, here are some imporant lines:
A new instance of the activity will always be immediately created after this one's onDestroy() is called. In particular, no messages will be dispatched during this time (when the returned object does not have an activity to be associated with). The object you return here will always be available from the getLastNonConfigurationInstance() method of the following activity instance as described there. These guarantees are designed so that an activity can use this API to propagate extensive state from the old to new activity instance, from loaded bitmaps, to network connections, to evenly actively running threads.
Answered By - wtsang02
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.