When I press back or home in my application, it hides, but the MediaPlayer keeps going. Is there a way to know when these buttons have been pressed and stop playback before closing?
+1
A:
You should be able to override the onPause()
function in your Activity
. onPause()
will be called when you Activity
is hidden and you can pause the MediaPlayer
there.
For example,
@Override
protected void onPause() {
super.onPause(); // Don't forget this line
myMediaPlayer.pause() // Or whatever the function is to pause it
}
Computerish
2010-09-12 17:57:59
This causes a crash.
Joel Auterson
2010-09-12 19:03:56
@Joel Can you provide more details, such as a stack trace?
MatrixFrog
2010-09-12 20:12:30
I'm now not totally sure that this was what was causing the crash. Let me get back to you...
Joel Auterson
2010-09-12 21:25:12
devvy is correct. I updated my post with more information.
Computerish
2010-09-13 01:26:00
+1
A:
Don't forget to add super.onPause; if you forget it will cause a FC.
devvy
2010-09-12 22:16:32