title: Call alertDialog onStop/onPause
body: <pre><code>@Override
  protected void onStop() {
      super.onStop();
  
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      builder.setMessage("Test message")
             .setCancelable(true)
             .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int id) {
                     dialog.cancel();
                 }
             });
      AlertDialog alert = builder.create();
      alert.show();
  }
  </code></pre>
  
  <p>This obviously isn't working, as soon as dialog is shown - activity is stopped (dialog disappears). How to solve this issuse?</p>
  
  <p>I want to save some setting into my database as soon as activity is left (via back button, clicking on some button which leads to some other activity, click on notification and so on..) and then show the result in AlertDialog?</p>
  
  <p>Or even better - when Android recognizes that activity will be closed, it saves my settings, show AlertDialog and then onClick Activity is finally closed.</p>