SetRetainInstance does not work for ListFragment when using compatibiltiy library

I am trying to keep a subclass of ListFragment to change orientation, so I added setRetainInstance (true) to the end of my onCreate function. I added the onSaveInstanceState method to add all its data to the package, and then added the code to onActivityCreated to load this data. Unfortunately this will not work.

When I added some debugging messages using Log.d, I found that not only the onSaveInstanceState called was not called, but onCreate (which apparently says the documentation should not happen when preserveInstance is true). Neither onCreate nor onActivityCreated have packages with my data (not surprisingly).

I suppose this might be a compatibility library issue, although I don't have an Android device version 3.0+ to test this.

Any help is appreciated, and I can post some code snippets if necessary, although I am not doing anything complicated.

Update: onDestroy is not called when I change orientation (as it should be), so it seems that some of setRetainInstance are working

+5
source share
2 answers

- , . , . FragmentActivity onSaveInstanceState, super.onSaveInstanceState. -, , , onSaveInstanceState , , setRetainInstance . , - , , .

+10

, setRetainInstance = true, onSaveInstanceState(), onActivityCreated(), Bundle .

, ListFragment , onActivityCreated().

, Activity .

+1

All Articles