I have an AlertDialog.Builder displaying on an application. When I rotate the screen, I get "application has leaked window" error. How do I cancel the AlertDialog in the onPause() event? I don't see any method for Ad.cancel().
Update: code edited for working model.
private AlertDialog inputDlg;
...
@Override
protected void onPause ()
{
// close dialog if it's showing
if (inputDlg != null)
if (inputDlg.isShowing ())
inputDlg.dismiss ();
super.onPause ();
}
...
private void dlgUserPrompt (Context c)
{
// Set an EditText view to get user input
final EditText input = new EditText (c);
AlertDialog.Builder Ab = new AlertDialog.Builder (this);
Ab.setTitle("title");
Ab.setMessage("I won't explode if you rotate this");
Ab.setView(input);
inputDlg = Ab.show ();
}