Reputation: 485
If I have
private AlertDialog somePrompt;
and later I call
somePrompt.dismiss();
or
somePrompt.cancel();
this will crash the app if the dialog was not previously shown like somePrompt.show()
. I need to make sure that this dialog is cancelled or dismissed, so how do I check if it is shown/visible?
Upvotes: 0
Views: 930
Reputation: 44571
Most likely your app is crashing because you aren't initializing your AlertDialog
in these cases since you aren't calling show()
on them. You probably only initialize them just before calling show(). You need to check if they are
null` before calling these closing methods on them.
if (somePrompt != null)
{
somePrompt.dismiss();
}
If this doesn't help then please post your logcat from the crash.
Also, if you need to see if it is shown before calling it then you can add an isShowing check
if (somePrompt != null && somePrompt.isShowing())
{
somePrompt.dismiss();
}
Upvotes: 1