Android: Why DialogFragment return nullpointer on orientation change

前端 未结 2 1718
陌清茗
陌清茗 2021-01-27 07:59

I have a problem with correct dialog fragment dismissing after that orientation was changed. I guess that\'s due to old context because after that activity was recreated there w

相关标签:
2条回答
  • 2021-01-27 08:28

    Fix is found. Maybe, it's already was written in the one of the fixes of google community which helps to avoid simple dismissing on orientation change and I miss it.

    I don't know already. In my case, I have set setRetainInstance(true) in onCreate method of DialogFragment.

    Implemented onDismiss method with simple fix and my last minor problem was that I didn't remove super.onDestroyView() in onDismiss method. Now it's working like a charm.

    0 讨论(0)
  • 2021-01-27 08:39

    Remove the setRetainInstance(true); from onCreateDialog(Bundle savedInstanceState) and keep it in onCreate(Bundle savedInstance) as follows :

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
    }
    
    0 讨论(0)
提交回复
热议问题