Override Dialog's OnBackPressed
<p>How can I specifically override just the back button while within a dialog to finish the entire activity and not just the dialog.</p>

<p>Using setOnCancelListener and setOnDismissListener do not work because there are other times that I simply close the dialog without closing the whole activity behind it.</p>

<p>Edit</p>

<p>Thanks Shubayu that may work!</p>

<p>I was also able to access just the back button in a dialog through this function.</p>

<pre><code>dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
    @Override
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK){
        finish();
        }
    return false;
    }
});
</code></pre>
