GPS Icon Won't Disappear When Activity Destroyed?
Solution 1:
I believe it is because you are using MyLocationOverlay
and have enableMyLocation()
:
MyLocationOverlay myLocOverlay = new MyLocationOverlay(this, mapView);
myLocOverlay.enableMyLocation();
mapOverlays.add(myLocOverlay);
If you remove that line of code everything will work fine. In the OnPause() you want to call:
myLocOverlay.disableMyLocation();
and in onResume()
call:
myLocOverlay.enableMyLocation();
Solution 2:
Following works, provided you store the MyLocOverlay
Object as class variable "myLocOverlay" in your Activity.
Prefer using onStop()
over onPause()
to avoid unnecessarily stopping and restarting the localization. onStop()
is called when "the activity is no longer visible to the user".
@Override
protected void onStop() {
super.onStop();
myLocOverlay.disableMyLocation();
mapOverlays.remove(myLocOverlay);
}
I do not have enough reputation to write a comment, but: "magaios" answer is wrong as seen in this official example.
super.onPause()
should be called first.
Solution 3:
You are calling super.onPause()
before removing updates! Your Activity
is never getting around to it. Switch it around:
locationManager.removeUpdates(this);
super.onPause();
Post a Comment for "GPS Icon Won't Disappear When Activity Destroyed?"