title: How to safely dismiss DialogFragment in onstop()?
body: <p>I need to dismiss DialogFragment in onStop() of an FragmentActivity if it is showing, this is what I did</p>
  <pre class="lang-java prettyprint-override"><code>if(mAlertDlg != null &amp;&amp; mAlertDlg.getDialog() != null)
      mAlertDlg.dismiss();
  </code></pre>
  <p>But I usually got IllegalStateException. So please tell me why that code is wrong and what is the correct way to dismiss DialogFragment in onStop()? Thank you.</p>