I have been trying to figure out why my app's Master Activity which also has a Master Fragment cannot seem to restore any state nor can its activity.
I have looked at example code from the Big Nerd Ranch book, The Busy Coder's Guide to Android Development, tons of the android docs, google searches, etc. I even tried just using the default Master Detail Flow in Android studio to ensure what I am seeing is real.
I have tried a static and dynamic fragment for the main fragment, I have played with variations on adding to the back stack, etc.
Using the Android Studio Master Detail flow template, when I click on a list element to start the detail activity, I can see that:
D/ItemListActivity: onSaveInstanceState:
is called. However, when you go back from the detail view to the master list, ItemListActivity is constructed and onCreate is called, but savedInstanceState is null. onRestoreInstanceState is never called.
D/ItemListActivity: ItemListActivity()
D/ItemListActivity: onCreate: (savedInstanceState == null) = true
I see basically the same with my own app:
When I touch a list element:
D/MainActivity: onSaveInstanceState
D/MainFragment: onSaveInstanceState
when I then touch Back to go back to the Main Activity list view, see:
D/MainActivity: onDestroy:
D/MainActivity: MainActivity()
D/MainActivity: onCreate: (savedInstanceState == null) = true
D/MainFragment: MainFragment()
D/MainFragment: onCreate: savedInstanceState = null
D/MainFragment: onCreateView: savedInstanceState = null
D/MainActivity: onResume:
Surely the answer is not to store my main activity/fragment state in a singleton injected by Dagger.