0

I am trying to use a theme tune throughout all my activities. From other Stack Overflow questions it has been suggested that a Service is the correct way to do this. In order to stop the theme tune from playing I need to detect when an activity is executed that isn't part of my application.

Is there any way to do this?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Ash McConnell
  • 1,340
  • 1
  • 17
  • 28

1 Answers1

0

Can't you just use onPause() and onResume(), etc for all your activities and keep track of whether they're still being used or not and send a message to the service or something? I don't think you can tell when other apps are being used that elegantly but I may be very wrong...

There's also onAudioFocusChange(etc) which lets you detect if something else is trying to play music...

karnok
  • 1,202
  • 1
  • 12
  • 17
  • Hmm, you'd hope there would be an elegant way to do this, it's quite a common use-case to play music in the background for a game. I suppose an alternative is to use a single Activity – Ash McConnell Jul 06 '11 at 09:52
  • Yeah, don't count on what I say... You've probably already seen this but it seems similar: http://stackoverflow.com/questions/1843911/android-detect-when-another-activity-is-launched-or-your-activity-loses-focus – karnok Jul 06 '11 at 10:12
  • Thanks, I somehow missed that one, looks like it could do the job! – Ash McConnell Jul 07 '11 at 09:03