I have an Activity that implements LocationListener.

public class MyActivity extends MapActivity  implements
LocationListener

In my activity, I register a locationlistener in the onCreate()

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
distance, this);

In the onDestroy method, I'm removing the registration for my
locationlistener.

@Override
protected void onDestroy() {
    Utils.addDebugMsg(this,"onDestroy");
    lm.removeUpdates(this);
    super.onDestroy();
}
In my application, I can change the minTime and distance, so I re-
initialize my listener like this :

private void initializeGpsListener() {
    lm.removeUpdates(this);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
distance, this);
}
For debugging purposes, I write something to the screen whenever a
provider is enabled (in this case GPS).

    @Override
    public void onProviderEnabled(String provider) {
        Utils.addDebugMsg(this,"onProviderEnabled : " + provider);
    }

What I noticed is that sometimes, multiple instances of my activity
(or locationlistener) are "kept around". Each time I turn the GPS
provider on, instead of seeing 1 statement "onProviderEnabled : GPS",
I see several different instances of my Activity printing this line
(all at the same time).

I want to keep the listener around, as it needs to update the location
even when the activity is not in the front , so removing it in
onPause() is not an option.

How do I clean up these listeners ( = my activities), and make sure
that only 1 remains active throughout the application.



-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to