When I press the back button, while my app’s running, the onPause method gets called, but the onSaveInstanceState isn’t. Then, if I enter my app again, I receive a call to onCreate, which will re-run my initialization logic.
I would like to save the state, so I can restore it when the user enters the app again, however I’m not sure how to go about this. What use will the onCreate‘s Bundle be to me, since in onPause I can only save data through SharedPreferences? Or I shouldn’t rely on the Bundle at all, and just reinitialize from the SharedPreferences?
How could the reinitialization be handled best?
EDIT: I would prefer if the changes could persist only until the app is killed. Only for the application’s lifetime.
From the onSaveInstanceState API Page
As long as your activity is being killed and you have overridden the onSaveInstanceState correctly then it should be fired.
As for your recent edit (from the same API page)
onSaveInstanceState is best used for persisting state when an activity is killed, not so much just for storing state for the application’s lifetime.