frankiesardo / icepick

Android Instance State made easy
Eclipse Public License 1.0
3.75k stars 208 forks source link

icepick+dialogfragment=no state saved? #78

Closed oradkovsky closed 7 years ago

oradkovsky commented 8 years ago

Hi. I am using icepick extensively. What I've faced recently is something I cannot understand - it's either misuse on my end or bug of icepick. Context:

  1. Got base abstract class that inherits from DialogFragment and has Icepick.saveInstanceState call in onSaveInstanceState as well as Icepick.restoreInstanceState in onCreateView.
  2. Got concrete dialog class that inherits from the above abstract class
  3. Got something like "@State String mName;" in p.2

What I'm observing is that state (value of mName) is not saved when hosting activity and fragment gets killed. onSaveInstanceState (with Icepick.saveInstanceState) is called while activity/fragments are dying. onCreateView (with Icepick.restoreInstanceState) is called when activity gets recreated.

When I do something like "outState.putString("key", mName)" in onSaveInstanceState, and mName = savedInstanceState.getString("key") in onCreateView - it works perfectly.

frankiesardo commented 7 years ago

Closing this as stale issue