Why oncreate method called after startActivityForResult?

前端 未结 2 1143
北海茫月
北海茫月 2020-12-16 18:46

In my application i want to select image from Gallery and set the image in ListView. In my ListViewI have 16 rows. So when ever item click in

相关标签:
2条回答
  • 2020-12-16 19:18

    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

    0 讨论(0)
  • 2020-12-16 19:24

    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

    0 讨论(0)
提交回复
热议问题