Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fused location stops sending updates after several hours

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?

like image 542
Nininea Avatar asked Oct 29 '25 09:10

Nininea


1 Answers

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.

like image 78
pepela Avatar answered Nov 01 '25 00:11

pepela