title: onDestroy mediaplayer release
body: <p>I want when I click on back button on the phone to close current activity and get back to menu and stop Media Player<br>
  But I get error: <code>Unfortunately Weapons has stopped! upon clicking on back button</code><br>
  So how to fix that?</p>
  
  <pre><code>public class pushke extends Activity {
  
      private SeekBar volumeSeekbar = null;
      private AudioManager audioManager = null; 
      MediaPlayer mp;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setVolumeControlStream(AudioManager.STREAM_MUSIC);
          setContentView(R.layout.guns);
          initControls();
  
          final MediaPlayer mp=MediaPlayer.create(this, R.raw.uzi);
          ImageButton btn1 = (ImageButton) findViewById(R.id.btn1);
  
          btn1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  if (mp.isPlaying()){
                      mp.pause();
                      mp.seekTo(0);
                  }
                  else{
                      mp.start();
                  }
              }
          });
      }
  
      private void initControls()
      {
          try
          {
              volumeSeekbar = (SeekBar)findViewById(R.id.seekBar1);
              audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
              volumeSeekbar.setMax(audioManager
                      .getStreamMaxVolume(AudioManager.STREAM_MUSIC));
              volumeSeekbar.setProgress(audioManager
                      .getStreamVolume(AudioManager.STREAM_MUSIC));   
  
  
              volumeSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() 
              {
                  @Override
                  public void onStopTrackingTouch(SeekBar arg0) 
                  { }
  
                  @Override
                  public void onStartTrackingTouch(SeekBar arg0) 
                  { }
  
                  @Override
                  public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) 
                  {
                      audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                              progress, 0);
                  }
              });
          }
          catch (Exception e) 
          {
              e.printStackTrace();
          }
      }
  
      @Override
      protected void onDestroy() {
          // TODO Auto-generated method stub
          super.onDestroy();
          mp.release();
      }
  }
  </code></pre>
  
  <p><strong>Logcat:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/56TSi.png" alt="enter image description here"></p>