Reputation: 7247
Im using Google Play Services, Fused Location Provider and LocationRequest to get the current location.
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setNumUpdates(1);
mLocationClient.requestLocationUpdates(mLocationRequest, this);
I would like to know how do I go about cancelling a request in progress? As stated by documentation when I call setNumUpdates() and pass 1, I must set an expiration which is fine while the app is running but what if I go to paused state? How can I explicitly cancel the request as the docs mention as soon as paused state occurs?
Thanks for reading
Upvotes: 1
Views: 4368
Reputation: 103
Just stop it like this, using the instance of your
fusedLocationClient.removeLocationUpdates(locationCallback);
See the documentation: https://developer.android.com/training/location/request-updates
Upvotes: 1
Reputation: 6435
If you are calling mGoogleApiClient.connect(); at onStart(), do that on onCreate(), and setNumUpdates will called only once.
Upvotes: 2