onSaveInstanceState is not getting called

后端 未结 3 2013
南旧
南旧 2021-01-14 00:40

I have an activity which starts various activities for result codes and on getting results in onActivityResult method it starts appropriate activity based on re

3条回答
  •  野的像风
    2021-01-14 01:08

    The method onSaveInstanceState() isn't called when an Activity finishes naturally like on a back button press. That's your app itself destroying the Activity. The method is only called if the Android OS anticipates that it may have to kill your activity to reclaim resources.

    If the Activity then actually gets killed by Android, the OS will make sure you receive a call to onRestoreInstanceState() as well passing the same bundle you used to save your activity's state in onSaveInstanceState() method.

    From the docs:

    This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state. For example, if activity B is launched in front of activity A, and at some point activity A is killed to reclaim resources, activity A will have a chance to save the current state of its user interface via this method so that when the user returns to activity A, the state of the user interface can be restored via onCreate(Bundle) or onRestoreInstanceState(Bundle).

提交回复
热议问题