0

I have an Activity A and Activity B.

In Activity A audio record and playback performs and on the press of back button audiotrack and audio record stops without any issue, but the main problem is in Activity B there is a video,when the footage of the video ends it moves back to Activity A.

Now the issue is at this time when I press back button the voice playback starts, means audiotrack and audiorecord doesn't stops.

I have gone through activity life cycle but i didn't got the desired Activity.

public void onBackPressed() {

    super.onBackPressed(); 
    Intent intent = new Intent(); 
    intent.addCategory(Intent.CATEGORY_HOME); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    intent.setAction(Intent.ACTION_MAIN); 
    startActivity(intent); 
    m_aboutOnyx.stop(); 
    timer.cancel(); 
    if(c_b_left == 1 || c_b_Right == 1 || c_b_fart ==1 || c_b_transperant ==1 ||c_b_food ==1 ||c_b_thunder ==1 || c_b_thumbs_up ==1){ 
        timer1.cancel();     
    } 
    isRecording = false; 
    track.stop(); 
    track.release(); 
    record.stop(); 
    record.release(); 
    this.finish(); 

}
Sufian
  • 6,405
  • 16
  • 66
  • 120
Abhi
  • 433
  • 2
  • 7
  • 17

2 Answers2

1

This function will be called when you click the back button

@Override
public void onBackPressed() {
    super.onBackPressed();

   // Call your function to stop the audio recording here.
}

If you want to stop the audio recording when your activity goes to background, then :

@Override
protected void onPause() {
    super.onPause();
   // Call your function to stop the recordinhg here.

}

For more activity lifecycle functions.

Community
  • 1
  • 1
amalBit
  • 12,041
  • 6
  • 77
  • 94
0

try like this:

@Override
 public void onBackPressed() {
    if( mediaPlayer.isPlaying() ) {
      mediaPlayer.stop();
    }
    super.onBackPressed();
 }
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
  • but I am not using media player. – Abhi Jun 13 '14 at 11:04
  • public void onBackPressed() { super.onBackPressed(); Intent intent = new Intent(); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_MAIN); startActivity(intent); m_aboutOnyx.stop(); timer.cancel(); if(c_b_left == 1 || c_b_Right == 1 || c_b_fart ==1 || c_b_transperant ==1 ||c_b_food ==1 ||c_b_thunder ==1 || c_b_thumbs_up ==1){ timer1.cancel(); } isRecording = false; track.stop(); track.release(); record.stop(); record.release(); this.finish(); } – Abhi Jun 13 '14 at 11:09