title: Yes/NO Alert Dialog box in Android
body: <p>I want to Show an Alert Dialog Box in android on onBackPressed() event</p>
  
  <pre><code>DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
  
      //@Override
      public void onClick(DialogInterface dialog, int which) {
          switch (which){
          case DialogInterface.BUTTON_POSITIVE:
              //Yes button clicked
              break;
  
          case DialogInterface.BUTTON_NEGATIVE:
              //No button clicked
              break;
          }
      }
  };
  </code></pre>
  
  <p><strong>But I am getting error when executing it in onBackPressed() event</strong></p>
  
  <pre><code>@Override
  public void onBackPressed() {
      super.onBackPressed();  
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
          .setNegativeButton("No", dialogClickListener).show();
  
  }
  </code></pre>
  
  <p>Error :
  "<em>com.java.mypkg has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406c3798 that was originally added here</em>"</p>
  
  <p>Do I have missed something. Pls help.</p>