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
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)
oronRestoreInstanceState(Bundle)
.