1

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

4

2 回答 2

2

如果您正在调用 mGoogleApiClient.connect(); 在 onStart() 上,在 onCreate() 上执行此操作,setNumUpdates 将只调用一次。

于 2016-01-19T10:41:36.620 回答
1

就这样停止它,使用你的实例

fusedLocationClient.removeLocationUpdates(locationCallback);

请参阅文档:https ://developer.android.com/training/location/request-updates

于 2020-10-12T20:40:24.753 回答