DialogFragment.dismiss crashing with NullPointerException

后端 未结 6 2024
慢半拍i
慢半拍i 2021-02-18 13:08

I\'m doing some background work and showing a DialogFragment while I do that. Once my work is done and the relevant callback is invoked, I dismiss the dialog. When I do, I get a

6条回答
  •  既然无缘
    2021-02-18 13:39

    Simplest solution is to check "getFragmentManager()" for "null" before calling "dismiss()" method. Also you can extend "DialogFragment" class and override method "dismiss()" to check it there:

    @Override
    public void dismiss()
    {
        if (getFragmentManager() != null) super.dismiss();
    }
    

提交回复
热议问题