title: How to check whether the navigation drawer is open?
body: <p>I have an activity with navigation drawer. Below is my code.</p>
  
  <pre><code>@Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
  
          if (keyCode == KeyEvent.KEYCODE_BACK) {
              if(dLayout.isDrawerOpen(GravityCompat.START)==true) {
                   dLayout.closeDrawers();
                  }
  
              else
              {
              doExit();
              }
          }
  
          return super.onKeyDown(keyCode, event);
      }
  
      private void doExit() {
  
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                  FirstSelection.this);
  
          alertDialog.setPositiveButton("Yes", new OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
          });
  </code></pre>
  
  <p>According to this code, when the user presses back button, the navigation drawer is closed if it is opened, else the <code>doExit();</code> method is called. But in my case, the else condition works fine, but when I press back button when the drawer is open, the complete app closes. I followed this code <a href="https://stackoverflow.com/questions/21633791/how-to-detect-if-navigation-drawer-is-open">How to detect if navigation drawer is open?</a></p>
  
  <p>Any help would be appreciated.</p>