DialogFragment lifecycle behavior
<p>I have a custom <code>DialogFragment</code> which overrides <code>onDismiss()</code> method: </p>

<pre><code>@Override
public void onDismiss(DialogInterface dialog) {
    ((MyActivity) getActivity()).onDismiss();
    super.onDismiss(dialog);
} 
</code></pre>

<p>The problem is that this method could be executed just after <code>onDetach()</code>, which in turn would trigger a <code>NullPointerException</code>. Is there a way to safely detect a dialog dismissal before it's detached?</p>