title: How to stop media player in new activity in Android
body: <p>I am a newbie to Android and have got stuck at <strong>stopping media player within the same activity</strong>.<br>
  I want to create an app that plays different music for different activities.<br>
  I am unable to stop the music once the first activity is created.<br>
  Even when I quit my app, the music is still playing.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class LayoutThreeActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.layout_three);
  
  }
  
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.layout_three, menu);
      return true;
  
  
  }
  
  
  public void openNewActivity(View view) {
      // Do something in response to button
      Intent intent = new Intent(this, LayoutOneActivity.class);
      startActivity(intent);
  
  
      MediaPlayer mp = MediaPlayer.create(this, R.raw.song2);
      mp.start();
  }
  </code></pre>