I have been working on a Location-based app, and everything is ok except for the location implementation, which is the core point.
I know location is very expensive, but I couldn't handle this by taking into account battery consumption.
Here is my current algorithm:
Step 1: Create an alarm manager with time interval of 1 minute.
Step 2: When alarm is triggered, start the location listener
if(settings.getBoolean("use_gps", false))
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,listener);
manager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0,listener);
Step 3: Wait a max of 15 seconds for a location
Step 4: When a location is received, stop the location listener..
One of the problems is due to this: at 0 seconds,with 0 meters location accuracy, CPU usage increases tremendously -- 45% CPU when alarm is triggered, with 0-15 seconds of alarm.
But when I look at battery usage of my app, the battery usage increase, after 1-2 hours, does not match the expectation: battery usage is only ~ 4% - 5%.
The second problem comes when the user wants to get their location by GPS. Because getting a location by GPS takes so long, compared with getting location from the network provider, I couldn't get the location by GPS.
I have implemented this algorithm after implementing a lot of different methods.
I am looking for recommendation from someone who has successfully implemented periodic location retrieval via GPS with low CPU usage.