0

I tried to add some Music in the Background of my Main Menu. I finally achieved it by using extends Service. Now i have another problem:

If the Home Button is pressed, the Service still runs and plays music, it only finishes, if i destroy it. I tried using:

@Override
protected void onPause(){
super.onPause();
service.setAction("model.BackgroundSound");
stopService(service);
}

which works fine, but if i switch from my Main Menu to my Character Selection Activity, it will pause too. But i would like to keep the music going in all Activities. Is there a way to detect the difference of the App being "on pause" or just the activity?

Tehc
  • 669
  • 3
  • 10
  • 28

2 Answers2

0

You can use fragments instead of Activities and it will call your Pause() just for the Single Activity.

Niral Bhavsar
  • 519
  • 1
  • 6
  • 13
  • Sorry but i only started learning Android programming like 1-2 Weeks ago and never really used fragments. How can i use fragments instead of Activities? – Tehc May 27 '16 at 12:42
  • https://developer.android.com/guide/components/fragments.html go through this link it will help you to learn about the fragments. – Niral Bhavsar May 27 '16 at 12:54
0

If you are using API level 14 and higher you can use registerActivityLifecycleCallbacks() on the Application. You can check and example usage in this SO answer.

This way you can check if any of your app's Activities is visible.

shelll
  • 3,234
  • 3
  • 33
  • 67