title: I want Activity to finish if i press ESCAPE button on an AlertDialog in an Activity
body: <p>I have 3 Activities <strong>A,B &amp; C</strong>.</p>
  
  <p>I present some video links in Activity <strong>A</strong> in a list. If user clicks on an item, i load Activity <strong>B</strong> in which i do some verification of user's data such as ask him to provide his Login info in an <strong>AlertDialog</strong>. I present two buttons in this dialog to <strong>Login</strong> &amp; <strong>Cancel</strong>. If user presses <strong>Login</strong> i verify his info and open Activity <strong>C</strong> where i play his selected video. But If user presses <strong>Cancel</strong>, i <strong>finish()</strong> Activity <strong>B</strong> to load Activity <strong>A</strong>.</p>
  
  <p>This works fine if user only interacts through burrons.</p>
  
  <p>But Issue arises that when i press <strong>ESCAPE</strong> button on my keyboard/D-Pad when the <strong>AlertDialog</strong> is open. The dialog disappears but the Activity <strong>B</strong> does not <strong>finish()</strong>. I have overridden <strong>onKeyDown</strong> of Activity <strong>B</strong> where i do the following.</p>
  
  <pre><code>@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK
              || keyCode == KeyEvent.KEYCODE_ESCAPE) {
          Log.d(TAG, "onKeyDown : calling finish() manually");
          finish();
          return true;
      } else
          return false;
  }
  </code></pre>
  
  <p>But it does not work WHEN i press <strong>ESCAPE</strong> on an open <strong>AlertDialog</strong>.</p>
  
  <p>How can i achieve this?</p>