I am trying to get a periodic update on location at a fixed interval. Right now, I am testing with a 2 minute interval just to make sure things are working. Then I will push it to a much longer interval.
Here is the relevant code:
public final int LOCATION_TIMER_RATE=120000;
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d("BLAH", "Recorded home location as: (" + location.getLatitude() + "," + location.getLongitude() + ")");
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_TIMER_RATE, 0, locationListener);
If I request a single update, as follows, I always get a response back within 20 seconds or so. But, after that, I still do not get my periodic updates:
locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, locationListener, null);
If you request a single update, do you need to reschedule your periodic updates?
If you request a single update, then yes, you’d have to reschedule it for future updates. As for the requesting period updates not being consistent, it says so in the documentation. The updates can take longer (or possibly even shorter) than the time period you select.