问题
I have been researching for hours to no avail. I'm trying to implement a simple background music to my app that will play across all activities and pause whenever the app is minimised.
However nothing seems to be working for me.
I have tried read and visited the following.
Android background music service
Play background music in all activities of Android app
Background music for game app that will play to all class
http://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App
And many many others but there is always one thing that doesn't seem to work.
Can anyone send an example of a 3 activity app that has background audio through all activities and pauses the music when the app is not visible?
回答1:
create a base activity and extend all other other activities from base activity and play bg music or whatever you want
public class BaseActivty extends AppCompatActivity{
@Override
protected void onPause() {
super.onPause();
// pause music
}
@Override
protected void onResume() {
super.onResume();
// play music
}
}
public class FirstActivty extends BaseActivty{
// perform other stuff here
}
hope that will help you...
来源:https://stackoverflow.com/questions/33032290/android-play-background-music-that-will-play-across-all-activities