DialogFragment with setRetainInstanceState(true) is not displayed after the device is rotated

后端 未结 2 618
误落风尘
误落风尘 2020-12-24 15:13

I have a question regarding DialogFragment. I am trying to make a dialog that keeps it\'s state after the device is rotated. This dialog has a bunch of references to things

2条回答
  •  隐瞒了意图╮
    2020-12-24 15:53

    The dialog fragment should be preserved automatically as long as you do the following:

    1. If you call an Activity onSaveInstanceState(), make sure you call the super function!!!!. In my case, that was the key. Also make sure you do the same thing in the Fragment.
    2. If you use setRetainInstance, you need to manually store off the values. Otherwise, you should be able to not worry about it, in most cases. If you're doing something a bit more complicated, you might need to setRetainInstance(true), but otherwise ignore it.
    3. Some people have complained about a bug in the support library, where a dismiss message is sent when it shouldn't be. The latest support library seems to have fixed that, so you shouldn't need to worry about that.

提交回复
热议问题