tags:

views:

40

answers:

1

Hi, I have an activity A which invokes Activity B on Button Click,and a Button click on Activity B invokes Class C. When button is clicked in Activity B , B calls a static method in Class C which passes its reference as one of the argument to method in C and other argument is path to the sound file that needs to be played. Once control reaches class C , Audio is played. But when Backkey is pressed Audio doesnot stop it continuous to play. How can I make the Audio to stop when BackKey is pressed. More over when Backkey is pressed control is coming to Activity A instead of Activity B. Can any one help me in solving this issue?

class activityA extends Activity
{ startIntent(ActivityB) on ButtonPress
}

class ActivityB extends Activity
{ classc.playAudio(ActivityB.this,audiopath);
}

class c
{ playAudio(Activity a, audiopath)
{ sound code to play audio is done here.
}
}

A: 

Use this in C activity , trap back key when going back from activity C

@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { //stop your music here } return super.onKeyDown(keyCode, event); }

success_anil
but c is not an Activity. It is normal java class. So, how to override onKeyDown() in this class?
Android_programmer_camera
ok .. my friend do that in your activity B
success_anil
Don't track the back key. You will miss things like home. Instead do this in either onPause() or onStop() as desired.
hackbod
Well this could be alternative better strategy.. Thanks hackbod
success_anil