Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 468
Tima Avatar asked Nov 16 '10 18:11

Tima


People also ask

How do I stop location updates?

You can control what location information your phone can use. Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.

What is location manager in android?

android.location.LocationManager. This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to be notified when the device enters the proximity of a given geographical location.

How will you instantly get location manager object?

First, create a Location Manager object by calling the getSystemService() method and LOCATION_SERVICE as an argument. Call getBestProvider() to get the location in the form of a string. Now the provider to getLastKnownLocation() as an argument to get the location.

Which method is used to stop listening for updates?

This section shows how you can stop the updates in the activity's onPause() method.


1 Answers

You should call the method removeUpdates inside the method onPause:

@Override protected void onPause() {     super.onPause();     locationManager.removeUpdates(this);     Log.i(TAG, "onPause, done"); } 
like image 56
bpz Avatar answered Sep 20 '22 22:09

bpz