I have an application that is running as a background service and constantly listens to network updates (course location). The service itself doesn’t hold any wake locks. The listening part looks like this:
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 120000, 3000F, this);
My onLocationChanged() method is doing some very simple stuff (just calculating distance to a pre-configured location using Location.distanceTo():
When looking into the battery stats, the application is a rock star – sometimes even more than the display.
CPU is not that bad but the “Stay Awake” part is very high.
Is there a way to prevent this?
I thought to use the AlarmManager to request an update every 2 minutes and then go to sleep after I get it, but I’m not sure that this is a good approach.
Also, I thought to detect when the device is in motion, but this will most probably be even a larger killer.
I think you answered your own question.
That would be the best approach. But don’t set it to two minutes, set it to 10 minutes intervals.