title: How to show a dialog box after pressing the back button
body: <p>By clicking the back button, I want to display a dialog box consisting of TextViews and a button called exit.
  After clicking the exit button it should come out from my app</p>
  
  <p>I did like this,</p>
  
  <pre><code>@Override       
  public void onBackPressed() {       
      System.out.println("hiiii");
      final Dialog dialog = new Dialog(this);
      dialog.setContentView(R.layout.dialog);
  
      Button exitButton = (Button) dialog.findViewById(R.id.exit);
      System.out.println("inside dialog_started");
      exitButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View arg0) {
              MainActivity.this.finish();
              dialog.dismiss();
          }
      });
      return;
  }
  </code></pre>
  
  <p>in log cat hiiiii and "inside dialog_started"  is printed, but dialog box is not coming.
  How can i get that dialog box on back button click?</p>