Why oncreate method called after startActivityForResult?

余生长醉 提交于 2019-11-29 10:08:15
Tal Kanel

before the onactivityresult(). But after oncreate() method again startactivity result called

when Activity is sent to background (when other activity becomes on top of it, or when it is sent by the home button to background) its instance is kept alive as long as the system is not under memory pressure. when the system doesn't have enough memory to do whatever it's currently doing in foreground, it usually will re-claim memory by stopping and releasing from memory background activities.

in that case - the system provide you with the Activity.onSaveInstanceState callback which will be invoked from the activity that's going to be killed to provide you a chance to save any state needed to be saved before it's being killed.

when your activity will return to foreground - it will be re-created (that's why onCreate() called again), with savedInstanceState parameter that will not be null.

the savedInstanceState will hold bundle with all the extras you provided in the onSavedInstanceState() callback.

this is very important to understand.

for better understanding, I advise you to read seriously - http://developer.android.com/training/basics/activity-lifecycle/recreating.html

May be dialog with selection chooser is too huge for the system and it reduces memory by caching your application. Check is method onSaveInstanceState called before onCreate. If yes, then you can save needed data in bundle and load it in onCreate method

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