Saving and restoring state is meant to save the current temporary data that is obsolete when user exits the application.
When you minimize or leave the Activity by opening next one it might be killed by the system due to lack of resources and restarted with savedInstanceState
when you get back to it. So use onSaveInstanceState()
only for saving minimize-restore session data or data that should be preserved on rotation.
So if you start a new Activity in front and get back to the previous one (what you are trying to do), the Activity A might not be killed (just stopped) and restarted without going being destroyed. You can force killing it and restoring by checking Don't keep activities
in developer options menu.
If you call finish()
or remove the Activity
from recent task list the savedInstanceState
will not be passed to onCreate()
since the task was cleared.
If the value must be persistent consider using SharedPreferences.