Android: Why DialogFragment return nullpointer on orientation change

前端 未结 2 1747
陌清茗
陌清茗 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: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);
    }
    

提交回复
热议问题