On Sun, Dec 5, 2010 at 4:02 PM, CChange <[email protected]> wrote: > I am writing a little app, that needs to poll location every n minutes > (usually every 15 or 30 minutes), do some logic with that information > and store something into the db. There is a GUI to all that of course, > but obviously I dont want that to run in the background as well. Just > the polling and that little logic. > > So my main question in regards to that, how would you write that if > you wanted to keep bat usage low. > > At first I thought about the > > LocationManager.addProximityAlert(..) method, but then I read that > that will be polled every 4 minutes which I dont need. Or does that > not use additional battery because the phone notifies all listeners > anyway?
It will only notify you when the user gets within such-and-so distance of a particular point, which does not seem to fit your desired functionality. > Or should I try to create a kind of service thread that polls every > (n) minutes and sleeps in between, would that save battery? Yes, but it will waste RAM and cause you to be the target of task killers. The ideal answer is to use AlarmManager, so your service only runs when it is actually collecting data. For GPS, though, this is tricky -- you do not want the GPS radio on all of the time (big battery drain), and there are a lot of edge cases (e.g., user has GPS disabled, user is in a large building and cannot get a GPS signal). I've been working on a WakefulLocationService that fits your desired functionality, but it hasn't been a high priority, so it is still in pieces on the lab bench. Does anyone have something like this already implemented that they could share? -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android App Developer Books: http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

