title: How to prevent DialogFragment from being dismissed when activity gets resumed
body: <p>I have an <code>Activity</code> which shows a <code>DialogFragment</code> when an event occurs in the <code>Activity</code>. When my application is running the user can press home button to make the app run in background. When app is running in background, as soon as the event occurs, the activity should show the <code>DialogFragment</code>, so that when user resumes the app the dialog should be on top of the activity, however I am not getting the results I want. As soon as I resume the app from launcher icon or notification, the dialog does not appear on the activity.</p>
  
  <p>Here is my DialogFragment class:</p>
  
  <pre><code>public static class MyDialog extends DialogFragment {
  
      public static DialogInterface.OnClickListener mListener;
      public static String mTitle, mBody;
      public static boolean mConfirm;
  
      public static MyDialog getInstance(String body, boolean confirm,
              DialogInterface.OnClickListener listener) {
          mListener = listener;
          mTitle = "MyDialog";
          mBody = body;
          mConfirm = confirm;
          MyDialog fragment = new MyDialog();
          return fragment;
      }
  
      @Override
      public Dialog onCreateDialog(Bundle savedIntanceState) {
          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
          .setTitle(mTitle).setMessage(mBody)
          .setPositiveButton("Ok", mListener);
          if (mConfirm)
              builder.setNegativeButton("Cancel", mListener);
          return builder.create();
      }
  }
  </code></pre>
  
  <p>The dialog works fine when activity is in foreground.
  Here is how I show the dialog:</p>
  
  <pre><code>MyDialog.getInstance("This is dialog body text", true, 
                  new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          if (which == DialogInterface.BUTTON_POSITIVE) {
                              // positive button pressed
                          }else //negative button pressed
                      }
          }).show(getSupportFragmentManager(), "dialog");
  </code></pre>
  
  <p>I want a dialog that remains on the activity even if the activity is in background, and as soon as I resume the activity, the dialog should be on top of the activity. How can I achieve this behavior?</p>