Don't know why, but sometimes LocationManager is still working also after closing application.
I call startGPS() in onCreate-Methode in one Activity (only one, let me call it StartActivity).
protected void startGPS()
{
try
{
lmanager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lmanager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
lmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
catch(Exception e)
{
e.printStackTrace();
}
}
And if this activity will be destroyed (so, when application will be closed), I call endGPS()
public void endGPS()
{
try
{
lmanager.removeUpdates(this);
lmanager=null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
Some ideas, some suggestions, what have I done wrong?!
You should call the method
removeUpdates
inside the methodonPause
:I use: locationManager.removeUpdates(locationListener); Its Working
The emulator never gets rid of the GPS icon once loaded. Hence, on an emulator, you cannot use the GPS icon as a test as to whether GPS is still running. On a device, though, the icon should vanish.
I sure would. I do not know whether
removeUpdates()
will remove both, or even if both requests are registered with the single listener.Is it possible your activity isn't being destroyed? i.e.: you hit the home button. Move your gps start/stop to
onStart
andonPause
.I see it´s been a while since this post, but maybe it would help some body else. I use: removeUpdates(this), because my listener it´s the activity where I implement de location manager, you need to indicate your listener.