问题
I am using this piece of code to stop gps locating the problem is that sometimes android kills my process starting it again... and the handle becomes invalid...making it impossible to stop the gps...how can i do this ?
here is the code:
lm.removeUpdates(locationListener);
locationListener = null;
回答1:
Try-
locationManager.removeUpdates(locListener);
if (locListener != null) {
locListener = null;
}
if (locationManager != null) {
locationManager = null;
}
And make sure you initialize your handler in onResume() and not onCreate()
Also put the above piece of code in onLocationChanged() since, as you've got the location, you don't need gps (for quite some time at least) as you said.
来源:https://stackoverflow.com/questions/9738980/gps-location-listener-stop