onPause, onResume etc. going around in circles :-(
<pre><code>public class HelloActivity extends Activity implements OnCompletionListener {
/** Called when the activity is first created. */
MediaPlayer myMediaPlayer;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v("CITIZEN","HLO: Start");
    setContentView(R.layout.hello);  // Inflate the hello.xml file in res/layout
    myMediaPlayer = MediaPlayer.create(this, R.raw.audiohello1);
    myMediaPlayer.setOnCompletionListener(this);
    myMediaPlayer.start();
    Log.v("CITIZEN","HLO: Playing Media");
}

// Now have manners!
// If the activity is paused, do it gracefully
// by using onPause(), onResume()

@Override
public void onResume()
    {  // After a pause OR at startup
    super.onResume();
    Log.v("CITIZEN","HLO: OnResume() Start");
    if (myMediaPlayer != null)
        {
        Log.v("CITIZEN","HLO: onResume() Not null");
        if (myMediaPlayer.isPlaying() == false)
            myMediaPlayer.start();
        }
    }

@Override
public void onPause()
    {  // We have disappeared into the background OR finish() has been called
    super.onPause();
Log.v("CITIZEN","HLO: onPause() Start");
    if (myMediaPlayer != null)
        {
        Log.v("CITIZEN","HLO: onPause() MediaPlayer Not null");
        if (myMediaPlayer.isPlaying() )
            myMediaPlayer.stop();
        }
        Log.v("CITIZEN","HLO: onPause() End");
    }

public void onCompletion(MediaPlayer mp)
    {  // The audio is complete, so time to wrapup and goo to next activity
    Log.v("CITIZEN","HLO: OnCompletion() Start");
    if (mp != null)
        {
        if (myMediaPlayer.isPlaying() )
            mp.stop();
        mp.release();
        mp = null;  // I put this in as an attempt to flag that audio had been released
        }
    Log.v("CITIZEN","HLO: End Media Player");
    // Now go to CameraWaitActivity
    Intent intentNextActivity;
        intentNextActivity = new Intent(HelloActivity.this, CameraWait1Activity.class);
     intentNextActivity.putExtra("TYPE", strUserType);
     intentNextActivity.putExtra("NEWS", strNewsType);
     intentNextActivity.putExtra("CATEGORY", strCategoryType);
     startActivity(intentNextActivity);
    Log.v("CITIZEN","HLO: Finish");
HelloActivity.this.finish();
    }
}
</code></pre>

<p>Here is the output from the CITIZEN filer</p>

<p>03-20 18:50:07.705: VERBOSE/CITIZEN(8608): SLCT: Novice</p>

<p>03-20 18:50:07.745: VERBOSE/CITIZEN(8608): SLCT: After spawning CONNECTING for a Novice</p>

<p>03-20 18:50:07.855: VERBOSE/CITIZEN(8608): CNCT: Connecting</p>

<p>03-20 18:50:07.885: VERBOSE/CITIZEN(8608): CNCT: UserType=NOVICE</p>

<p>03-20 18:50:07.905: VERBOSE/CITIZEN(8608): CNCT: Finish</p>

<p>$03-20 18:50:07.985: VERBOSE/CITIZEN(8608): HLO: Start</p>

<p>03-20 18:50:08.205: VERBOSE/CITIZEN(8608): HLO: Playing Media</p>

<p>03-20 18:50:08.205: VERBOSE/CITIZEN(8608): HLO: OnResume() Start</p>

<p>03-20 18:50:08.205: VERBOSE/CITIZEN(8608): HLO: onResule() Not null</p>

<p>03-20 18:50:25.565: VERBOSE/CITIZEN(8608): HLO: OnCompletion() Start</p>

<p>03-20 18:50:25.595: VERBOSE/CITIZEN(8608): HLO: End Media Player</p>

<p>03-20 18:50:25.625: VERBOSE/CITIZEN(8608): HLO: Finish</p>

<p>03-20 18:50:25.625: VERBOSE/CITIZEN(8608): HLO: onPause() Start</p>

<p>03-20 18:50:25.635: VERBOSE/CITIZEN(8608): HLO: onPause() MediaPlayer Not null</p>

<p>What am I tryng to do.  If the activity goes background I want to pause the audio and then resume when it gets foreground again.  The problem right now is that the activity aborts at the end of the audio instead of dying gracefully.  It would appear that the onPause() is being called after I call finish() for the activity and I am releasing the media player even though I had already released it just before finish().  How do I detect that the player has already been released in onPause() so that I dont try releasing something that is already released.</p>

<p>OR</p>

<p>Am I going about this in the wrong way altogether and using a sledgehammer to crack a nut??</p>

<p>Suggestions/comments, as always are very much appreciated (even to suggest that I am insane in what I am doing!),</p>

<p>Thanks,</p>

<p>Oliver</p>
