Reputation: 573
I am trying to create a basic app that simply turns on at 8:00 AM every weekday and checks GPS every 5 minutes until 8:55 AM at which the service would stop until 8:00 AM the next weekday. What is the best way to do this? I was thinking having a AlarmManager that would start a service that would set another AlarmManger for 5 minutes. When that alarmmanger launches the GPSService the GPSService would do it's thing and then set yet another alarmmanger to launch itself in 5 minutes until it calculates that it is pas 8:55 and simply not set another alarmmanager. But this can't be an efficient or best practice so any advice (preferably with code samples!) would be much appreciated.
Thanks. :)
Upvotes: 2
Views: 646
Reputation: 46856
There are other ways to achieve the same thing certainly. None of them are going to be particularly "effecient" in device terms since they are going to wake up the device and work with the gps radios every 5 minutes for a while, I don't think you'll get much better or worse with any of the possible ways to achieve it.
You could use setReapeating()
with a 5 minute interval time, and do the check in your service to determine if you need to un-schedule the alarm. If you are simply looking for a different way.
But honestly I don't see anything wrong with doing it the way that you described.
Upvotes: 1