If I left application turned on for several hours fused location stops sending updates...
I am creating location request with hight priority , here is code :
LocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setExpirationDuration(TimeUnit.SECONDS.toMillis(LOCATION_TIMEOUT_IN_SECONDS))
.setInterval(LOCATION_UPDATE_INTERVAL);
Here is client and callback :
LocationCallback mLocationCallback = new LocationCallback() {
@Override
public void onLocationAvailability(LocationAvailability locationAvailability) {
super.onLocationAvailability(locationAvailability);
}
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
//Update location
}
};
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
mFusedLocationProviderClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null);
LOCATION_TIMEOUT_IN_SECONDS is 5 second, but updates is not always running, I stop and start it manually, when my application needs location. Like it is documented .
Everything works fine if application is running one or two hours, but if I left it open for a long time, it stops working....
I requested location updates from Activity on button click, after 10 seconds, I stop location updates manually... If I left it whole night , this means that Activity is alive whole night... after this, when I request location updates again, it is not coming...
Any solution or idea?
setExpirationDuration(long millis)
from docs:
Set the duration of this request, in milliseconds.
The duration begins immediately (and not when the request is passed to the location client), so call this method again if the request is re-used at a later time.
The location client will automatically stop updates after the request expires.
The duration includes suspend time. Values less than 0 are allowed, but indicate that the request has already expired.
If you want to receive location updates forever, remove it or set appropriate time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With