Just wasted 3 hours trying to figure out why the GPS icon is still showing up in the notification bar when my map activity is paused. I've narrowed it down to having to do with the MyLocationOverlay object I'm using (I also have a LocationListener and a GpsStatus.Listener).
@Override
protected void onPause() {
super.onPause();
manager.removeUpdates(locListener);
manager.removeGpsStatusListener(statListener);
myLocOverlay.disableMyLocation(); //!doesn't seem to work
myLocOverlay.disableCompass();
}
If anyone has any idea why this is happening please help so I don't pull all my hair out. I can't release my app with a battery draining issue like this.
Issue was in my initilization of the MyLocationOverlay Object. Wrong Code:
private void initMyLocation() {
myLocOverlay = new MyLocationOverlay(this, mapView); //THIS SHOULD NOT BE HERE.
myLocOverlay.enableMyLocation();
myLocOverlay.enableCompass();
mapView.getOverlays().add(myLocOverlay);
}
My initMyLocation() function gets called multiple times through-out my code. Calling this line: myLocOverlay = new MyLocationOverlay(this, mapView); multiple times was creating multiple listeners that failed to be disabled with disableMyLocation() (i think...).
Anyways I moved the MyLocationOverlay initialization to onCreate() and now it works.
来源:https://stackoverflow.com/questions/6515923/mylocationoverlay-disablemylocation-not-seeming-to-work