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
This may also occur when you call dismiss() before you have called show() like Sogger said.
After Dialog object is constructed but before dialog is not showed, if (mDialog != null) can be passed and NullPointerException will occur.
When you check if mDialog is null or not,
if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
}
Add more conditions like below,
if ((mDialog != null) && mDialog.isAdded() && mDialog.isResumed()) {
mDialog.dismiss();
mDialog = null;
}
I think that mDialog.isAdded() condition might be enough...