title: Android: How to make AlertDialog disappear on clicking ok button?
body: <p>I am asking the same question which is asked before at below links but the solution proposed in these links is not working for me so I am posting it again.</p>
  
  <p><a href="https://stackoverflow.com/questions/7293936/how-to-make-an-alertdialog-disappear">How to make an AlertDialog disappear?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10810322/android-alertdialog-always-exits-when-i-click-on-ok-button">Android AlertDialog always exits when I click on OK Button</a></p>
  
  <p><a href="https://stackoverflow.com/questions/21546909/how-to-navigate-to-next-activity-after-user-clicks-on-alertdialog-ok-button">How to navigate to next activity after user clicks on AlertDialog OK button?</a></p>
  
  <p>Basically, I am creating an AlertDialog builder to notify the user for asking to enable a setting for the Usage Data Access and when the OK button is pressed then the Settings menu gets opened. When I press back button to come back on the app then the AlertDialog is still available there although I expected to be dismissed to be back on my app.</p>
  
  <pre><code>    public void show_alert(){
  
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage("This application requires access to the Usage Stats Service. Please " +
                          "ensure that this is enabled in settings, then press the back button to continue ");
      builder.setCancelable(true);
  
      builder.setPositiveButton(
              "OK",
              new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int id) {
  
                      Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
                      startActivity(intent);
                      dialog.dismiss();
                  }
              });
  
      builder.show();
      return;
  </code></pre>
  
  <p>}</p>
  
  <p>Any hint what wrong could be going here?</p>