title: how to pause media player sound in android
body: <p>I have media player in main activity. And sound start with this activity. I want when new activity start audio stop and when I press back from next activity and back to main activity audio starts. Please help me.</p>
  
  <p>Code-</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          mp = MediaPlayer.create(this, R.raw.test);
          mp.start();
          mp.setLooping(true);
          addListenerOnButton();
      }
  
      public void addListenerOnButton()
      {
          boy1 = (Button) findViewById(R.id.boy1);
          boy1.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View arg0) {
                  mp.stop();
                  startActivity(new Intent(Main.this, Boy1.class));
              }
          });     
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          mp.stop();
      }
  
      @Override 
      public void onBackPressed() {
          super.onBackPressed();
          mp.stop();
          finish();
      } 
  
      @Override 
      public void onResume()
      {
          super.onResume();
      }
  
      @Override
      protected void onStop() {
          super.onStop();
          mp.stop();
      }
  
  }  
  </code></pre>