Android - How to stop the music only when home button is pressed?

Check for activity going into background, explanation for this is here You can stop music when your app goes in background.

Check for activity going into background, explanation for this is here. You can stop music when your app goes in background.

You cant detect the home button pressed, but you can overload OnPause of your activity, and there turn off the music.

When the Home Button is pressed, the Stop method of the activity class is called. Here is how I stop a media player when home is pressed: @Override public void onStop(){ super.onStop(); stopMusic(); } Make sure you release the media player after you stop it.

I'm creating a simple game and the same background music is being played throughout its whole life. I'm using a static class to manage my MediaPlayer so the music can continue playing without being interrupted when the game switches between different Activities. The problem: when the user presses the Home button, I'd like to stop the music.

Doing this on onStop() or onPause() doesn't work in this case, as these events are also called at other times when creating, destroying or switching between activities. Is there any way I can create some code that is called only when the Home button is pressed, or maybe when the "whole app" loses focus?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions