title: how to resume my audio in Android?
body: <p>I have to implemented application for creating audio with the status of pause and resume and when my app as an when start the audio is start and when I press the back button on the emulator the audio music is on pause state but When my activity comes back to the foreground from the stopped state my audio music is not resumed. Here is my code.</p>
  
  <pre><code>public class Audio_Activity extends Activity 
  {
      private  MediaPlayer mp;
      Button btnStartStop ;
      Button btnChapter ;
      Button btnOne;
      Button btnTwo;
      Button btnThree;
      Button btnFour;
      Button btnFive;
      int length;
  
  
      ImageView imgVw;
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.audio);
          init();
  
          mp=MediaPlayer.create(Audio_Activity.this,R.raw.ennamo_yadho);
          Log.e("Song is playing","in  Mediya Player ");
  
          if(mp!=null)
          {
                  mp.setLooping(false);
                  mp.start();
                  btnChapter.setEnabled(false);
                  System.out.println("B4 button Click!!!!");
          }
  
          mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
          {
              @Override
              public void onCompletion(MediaPlayer mp) 
              {
                  mp.stop();
                  mp.release();
                  btnChapter.setEnabled(true);
                  System.out.println("Music is over and Button is enable !!!!!!");
              }
          });
  
  
          btnStartStop.setOnClickListener(new OnClickListener()
          {
              @Override
              public void onClick(View arg0) 
              {
                  if(mp.isPlaying())
                  {
                      if(mp!=null)
                      {
                              mp.pause();
                      }
  
                  }
  
                  else
                  {
                      // Resume song
                      if(mp!=null)
                      {
                              mp.start();
                      }
                  }
              }
          });
  
  
          btnOne.setOnClickListener(new OnClickListener()
          {
              @Override
              public void onClick(View v) 
              {
                  imgVw.setImageResource(R.raw.chocklate);
                  }
              }
          );
  
          btnTwo.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  imgVw.setImageResource(R.raw.creame);
              }
          });
  
          btnThree.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  imgVw.setImageResource(R.raw.schocklate);
  
              }
          });
  
          btnFour.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  imgVw.setImageResource(R.raw.pinapple);
  
              }
          });
  
          btnFive.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  imgVw.setImageResource(R.raw.strobery);
  
              }
          });
      }
  
       @Override
          protected void onResume() 
          {
              super.onResume();
              System.out.println("Activity is Resume !!!");
          }
  
      @Override
      protected void onStart() 
      {
          super.onStart(); 
          System.out.println("Activity is Started !!!");
      }
  
  
       @Override
          protected void onRestart() {
              super.onRestart();
              System.out.println("Activity is Re-Started !!!");
              if(mp.isPlaying())
              {
                  if(mp!=null)
                  {
                      length=mp.getCurrentPosition();
                      mp.seekTo(length);
                      mp.start();
                  }
              }
  
          }
  
  
  
          @Override
          protected void onPause() {
              super.onPause();
              System.out.println("Activity is Pause!!!");
          }
  
          @Override
          protected void onStop() {
              super.onStop();
              System.out.println("Activity is Stop !!!");
          }
  
          @Override
          protected void onDestroy() {
              super.onDestroy();
              System.out.println("Activity is Destroyed !!!");
          }
  
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) 
      {
          if ((keyCode == KeyEvent.KEYCODE_BACK)) 
          { //Back key pressed
             //Things to Do
              if(mp!= null)
              {
                  if(mp.isPlaying())
                  {
                      mp.pause();
                      //mp=null;
                  }
              }
              finish();
              return true;
          }
          return super.onKeyDown(keyCode, event);
      }
  
  }
  </code></pre>