0

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?

Community
  • 1
  • 1
xn1
  • 417
  • 4
  • 12

1 Answers1

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...

Mustanser Iqbal
  • 5,017
  • 4
  • 18
  • 36
  • So the base activity is responsible for initiating the service and controlling the music?? It can't be that simple can it? – xn1 Oct 09 '15 at 08:03
  • That's working really well now except for a stutter between activities. Is there a way of getting rid of that? – xn1 Oct 09 '15 at 09:35
  • 1
    sorry for late response i was away... for this problem you can start a service and it will solve your problem.. – Mustanser Iqbal Oct 13 '15 at 04:52
  • Thank you for your reply. I had managed to solve the problem and all is working perfectly. I can't believe how simple it all ended up being. – xn1 Oct 14 '15 at 10:26
  • 1
    Still have problem here. Problem is when you finish FisrtActivity. The method onDestroy of BaseActivty will be called and stop music. Question is : How to finish FristActivity without call onDestroy method of BaseActivity?? – Bulma Mar 11 '17 at 10:34