Unsubscribing a LocationListener from the LocationManager
Asked Answered
S

3

7

How do I unsubscribe a LocationListener from recieving updates from the LocationManager?

Here is how I'm setting it up

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 have exited the the view that created the LocationListener I am still getting log messages in the LogCat window.

I understand that this is because I am orphaning the listener but I cannot see any destroy method on the LocationListener nor can I see any "remove listener" style methods on the LocationManager object.

Suggest answered 19/1, 2010 at 22:1 Comment(0)
Z
16

Call removeUpdates on LocationManager, passing your location listener.

Zoosporangium answered 19/1, 2010 at 22:10 Comment(1)
Is there any way of doing this if you are not storing the listener as a member?Apery
L
6
mLocationManager.removeUpdates(mListener);
Lebrun answered 19/1, 2010 at 22:11 Comment(0)
C
3

I think removeUpdates should help.

mLocationManager.removeUpdates(mListener)
Cybill answered 19/1, 2010 at 22:11 Comment(1)
Is there any way of doing this if you are not storing the listener as a member?Apery

© 2022 - 2024 — McMap. All rights reserved.