Unsubscribe LocationListener from LocationManager

How do I unsubscribe LocationListenerfrom updates LocationManager?

This is how I configure it

mLocationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
mListener = new LocationListener() {
    public void onLocationChanged(Location location) {
        Log.i("LocationListener", "Logging Change");
    }

}

mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
                5000, 1, mListener);

After I left the view that created LocationListener, I still get the log messages in the LogCat window.

I understand that this is because I am an orphan of a listener, but I don’t see any destroy method in LocationListener, and I don’t see any delete listener style methods in the object LocationManager.

+5
source share
3 answers

Call removeUpdates on the LocationManager, passing in your location receiver.

+14
source
mLocationManager.removeUpdates(mListener);
+6

, removeUpdates .

mLocationManager.removeUpdates(mListener)
+3

All Articles