I have an android app that has mutliple activities
The first main activity starts background music using media player. How can I make this music continue playing while the app is im forground
I tried to stop the app on the onpause method and starts it on the onresume method but its cumbersome to have the same code in every activity
Thanks a lot
I have an android app that has mutliple activities The first main activity starts
Share
You cannot stop the Media Player in onPause if you want it to play untill the Application is in foreground. The reason is If you transit from Activity A to Activity B, the onPause of Activity A and onResume/onCreate of Activity B will be called. To achieve the things you want to implement, you will need to check when the application goes in the background. To do so, use the following functions :
And for Background :
To call this functions, Create a Base Activity and override their onPause() and onResume() method, Extend the Base Activity in place of Activity.
Hope this helps you.
Shraddha