I am storing data to the "outState" in this method:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("my_int", mValue);
}
This means, that when the activity is restarted, in the onCreate()
method, I can do:
if (null != savedInstanceState) {
savedInstanceState.getInt("my_int");
}
However, this leads to a problem after the screen is switched off. When the screen is switched off, the activity is killed. This means that onSaveInstanceState()
is not called if rotation occurs during the screen off period and the savedInstancestate
is null because the activity has been completely restarted. As a result, my value has not been saved and restored even though the device has been rotated.
How do I get around this?