Listing 3.7 Checking bundle in onCreate(…)


As per the book,
if (savedInstanceState != null) {
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);


If I implement as such in my code, the app is not remembering the data saved between rotations (which is what expected).
I found that if I put the code snippet just before “super.onCreate(savedInstanceState);” then it is working as expected.

This is what I currently have in my code.

protected void onCreate(Bundle savedInstanceState) {
if(savedInstanceState != null)
mCurrentIndex = savedInstanceState.getInt(KEY_INDEX,0);


Not sure whether there is a typo in the book or not ?


mine worked fine the way it was in the book. Are you sure you wrote everything down correctly from Listing 3.6?