How to capture an event when a user dismiss an alert dialog by pressing the backKey in Android
<p>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</p>

<pre><code>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();
}
</code></pre>

<p>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?</p>
