title: Android - How to detect the final Activity in the stack
body: <p>I use the code below to check the final <code>Fragment</code> in an <code>Activity</code> to pop a dialog</p>
  
  <pre><code>@Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          // Check if there is only one fragment
          if (keyCode == KeyEvent.KEYCODE_BACK) {
              if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
                  DlgUniversalError.shallIQuit(this, getApplicationContext()
                          .getResources().getString(R.string.doYouWantToQuit),
                          getSupportFragmentManager());
                  return false;
              }
          }
          return super.onKeyDown(keyCode, event);
      }
  </code></pre>
  
  <hr>
  
  <p>Now suppose i have a set of <code>Activity</code>s. How can I perform the same for an <code>Activity</code> whether the <code>Activity</code> is the last in the stack, and pop a quit dialog ?</p>