-1

I'm developing an application that takes the user through an exercise plan. It's a running trainer that uses audio cues to let the user know when to walk, run, etc. at different points during their exercise.

It's very likely that the phone will be locked and in someone's pocket while the app is running, so I'm looking into the ways I can keep the audible cues coming. At the moment I'm just testing using a Handler in a local Service to schedule the next cue along. That's working better than I expected on some devices, but, on others, the Service seems to stop when the phone is locked.

I know there are a variety of options open to me -- keep a wake lock on the phone, schedule alarms, (perhaps? Not sure on this one) changing the priority of the Service, and maybe more.

So, what do people think would be the best approach? Bear in mind that this is not a "normal" Service -- it will be typically be running for at most half an hour, three times a week, and many of its users will be playing music while they run, so the phone is fairly unlikely to be asleep anyway. I'm thinking, therefore, that the usual caveats about battery-draining wake-locks may not apply so much in this case?

Currently I'm targeting API level 8 as my minimum.

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128

1 Answers1

1

Depends on how much you have to do. If it's just playing some audio occasionally at certain intervals you could likely get away with an alarm that repeats. If you're also doing other things -- tracking things over GPS or some other mechanism, or anything that requires reasonable CPU -- a partial wake lock is likely the best option.

Brian Dupuis
  • 8,136
  • 3
  • 25
  • 29
  • Thanks for responding, Brian. I am just playing some audio occasionally -- probably averaging once every few minutes, but the intervals vary. Having done more research, my current Handler implementation isn't too far away from what I'd need to do with an AlarmManager alarm, though I'd need to take a bit more care (e.g. take out a wake lock on receiving the alarm and keep it open until the sound was finished playing) than if I just kept a CPU-only wake-lock open for the whole run. I'm not sure just how much battery I'm going to save the user, but I might as well try, right? – Matt Gibson Feb 09 '12 at 14:30
  • Yup. Always better to be a Good Citizen if you can help it. Good luck. – Brian Dupuis Feb 09 '12 at 14:32