In an android application, I'm showing to the user an AlertDialog with no buttons, just a message. How can I destroy the AlertDialog programmatically so that it's not visible anymore? I tried with cancel() and dismiss() but they are not working, the view remains there.
AlertDialog.Builder test = new AlertDialog.Builder(context);
test.setTitle("title");
test.setCancelable(true);
test.setMessage("message...");
test.create().show();
then I tried
test.show().cancel()
and
test.show().dismiss()
but not working.
add this
alertDialog.setCanceledOnTouchOutside(true);
to dismiss dialog if user touch outsideOR by click Device back button
You should refer to the AlertDialog itself, not the builder.
Later you want to hide it: