Tima Tima - 2 months ago 14
Android Question

How to stop location manager?

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?!

Answer

Is it possible your activity isn't being destroyed? i.e.: you hit the home button. Move your gps start/stop to onStart and onPause.

Comments