I need to save some state when the user leaves my game during game play. Saving the state doesn’t seem to be an issue, but I can’t figure out how to restore it. The onCreate function isn’t called when the Activity is resumed (only when it is first created), so I can’t get my state back there. Logically, I would use onRestoreInstanceState, but it isn’t being called.
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.d("RocketLaunch", "onRestoreInstanceState()");
savedState = savedInstanceState;
}
I see log output from onSaveInstanceState, onResume, onCreate, etc, but I never see a log message from onRestoreInstanceState and savedState is always null. Why isn’t onRestoreInstanceState being called, and is there another way to get my state back?
Thanks!
If the user leaves, I believe you need to take care of this in onPause and onResume. In my very limited testing over the last 30 seconds, I found that my onRestoreInstanceState was only called during an orientation change. (And possibly other similar actions)
Or perhaps in onPostCreate, which does give you the saved instanceState bundle.