I need to catch an event when the user presses the back key and try to dismiss the dialog I have a code like this
AlertDialog alertDialog = new AlertDialog.Builder(AppNotification.this).create();
alertDialog.setTitle("Caution");
alertDialog.setMessage("Alert");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
} });
alertDialog.show();
}
Now here i have given the user an option,But suppose if he presses the back key then i need to perform some other action.how to do it?
There is also
alertDialog.setOnDismissListener(dialog -> { /* code goes here */ });
which seems to be handling specifically the dismiss event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With