Wait for activity is destroyed
<p>I have a question about life cycle.</p>

<p>I have 2 activities. (Just call it A and B).
In A which is <code>MainActivity</code> I have a <code>button</code> that call Activity B.
At activity B, pressing back button will call the <code>finish()</code>.</p>

<p>The point is it's okay when I call <code>finish()</code>, wait a while and than call B again, it's okay.
But when I call <code>finish()</code> and immediately call B again than
previous B's <code>onDestroy()</code> is called <em>after</em> new B's <code>onCreate()</code>, <code>onResume()</code>.</p>

<p>It's problem for me because I handle some static <code>MediaPlayer</code> on <code>onResume()</code>, <code>onPause()</code>... everywhere.</p>

<pre><code>@Override
protected void onResume(){
    super.onResume();

    if (mediaPlayer != null)
        mediaPlayer.start();
}

@Override
protected void onPause(){
    super.onPause();

    if(mediaPlayer != null)
        mediaPlayer.pause();
}

@Override
protected void onDestroy(){
    super.onDestroy();
    if(mediaPlayer != null)
        mediaPlayer.release();
        mediaPlayer = null;
}
</code></pre>

<p>So if I press back and call B fast again, it resume the previous sound short and than stop.
Another class controls the <code>mediaPlayer</code> so I can't remove the <em>static</em> field.</p>

<p>I think I can handle this by waiting <code>onDestroy(</code>).
Is there any way to make MainActivity(A) to wait until B is completely destroyed?</p>