I know this question was asked earlier in stackoverflow, but the answers did not work for me.
Perhaps worth mentioning:
- I am using ActionBarSherlock with a support package.
- Method
onSaveInstanceStateCalled when the home button is pressed. The method onCreatealways always gives NULL for Bundle savedInstanceState. - The method is
onRestoreInstanceStatenever called at all. (I would not mind if I onCreateworked;)). - Also (it shouldn't matter) I tried to put it
super.onSaveInstanceState(outState)below onSaveInstanceState. Bad luck.
Here is the code. I hope someone had this problem and it was resolved.
public class MainActivity extends SherlockFragmentActivity {
private static final String LOG_TAG = MainActivity.class.getSimpleName();
private static String STATE_TO_STORE = "state_to_store";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(LOG_TAG, "onCreate: savedInstanceState = " + (savedInstanceState == null ? "NULL" : "Not NULL"));
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.d(LOG_TAG, "onRestoreInstanceState: savedInstanceState = " + (savedInstanceState == null ? "NULL" : "Not NULL"));
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_TO_STORE, 5);
Log.d(LOG_TAG, "onSaveInstanceState bundle: " + outState.toString());
}
}
The log clearly states what onSaveInstanceStateis being called, and onCreate gets savedInstanceState = NULL.
Almer