I have an application that is a menu with several options, every option when chosen will lead to a new activity.
I also have music playing in the background using a service. I want my music play continuously no matter what activity is focused.
My problem is:
- If I am NOT override onPause() or onStop(), the music will go fine when I open another activity. BUT when I press home button, music still plays.
- If I DO override onPause() or onStop(), the music will stop when I press Home button, but it also stops when another activity is opened.
So what should I do now?
You can override
onPause()and use a boolean flag.Set the boolean to
trueif you are launching a new activity. WhenonPause()is called you’ll know if it is nottruethen you should stop the music.