In my application, I’ve setup a location manager to update the current location every 10 minutes (or so I thought). Instead I’m getting updates every 5 minutes:
10-03 23:45:17.153: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-03 23:50:23.162: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-03 23:55:23.074: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
10-04 00:00:23.077: DEBUG/TheApp(2025): Location updated with accuracy: 48.0m
Here’s the code:
LocationManager locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d(APP_TAG, "Location updated with accuracy: " + location.getAccuracy() + "m");
}
//Other methods are empty and omitted for brevity
};
int TEN_MINUTES = 10 /*Minutes*/ * 60 /*sec per min*/ * 1000 /*ms per sec*/;
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
TEN_MINUTES, 0, locationListener);
Can anyone explain why this isn’t working as I thought? E.g. why its updating every 5 minutes instead of 10?
As noted in the documentation for LocationManager.requestLocationUpdates():
So, there’s no guarantee that you won’t get updates more (or less) frequently. It’s possible that the GPS chip is able to provide more accurate location information without consuming additional power or otherwise doesn’t allow the requested level of granularity. It’s also possible that another application is also requesting updates in the background.
Answering with more detail that that would probably require knowledge of how the specific GPS receiver in your phone works.