How to properly retain a DialogFragment through rotation?

后端 未结 3 424
我寻月下人不归
我寻月下人不归 2020-12-02 07:32

I have a FragmentActivity that hosts a DialogFragment.

The DialogFragment perform network requests and handles Facebook authentication, so I need to retain it during

3条回答
  •  悲哀的现实
    2020-12-02 08:00

    One of the advantages of using dialogFragment compared to just using alertDialogBuilder is exactly because dialogfragment can automatically recreate itself upon rotation without user intervention.

    However, when the dialogfragment does not recreate itself, it is possible that you overwrite onSaveInstanceState but didn't to call super:

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState); // <-- must call this if you want to retain dialogFragment upon rotation
        ...
    }
    

提交回复
热议问题