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 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.
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.
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.
This section shows how you can stop the updates in the activity's onPause() method.
You should call the method removeUpdates
inside the method onPause
:
@Override protected void onPause() { super.onPause(); locationManager.removeUpdates(this); Log.i(TAG, "onPause, done"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With