Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Location Listener in Android

In my android app I need to get current GPS location of the user at the start of the application only if location has change from the previous location. But the problem is when I inside the application if location change (ie If user was traveling while using the app) app is starting from the beginning.

I need to stop location listener after getting user current location. removeUpdates method didn't work for me.

Please help me on this issue. thanks in advance !

like image 644
Chrishan Avatar asked Aug 01 '11 04:08

Chrishan


People also ask

How do I turn off location listener on Android?

removeUpdates(locationListenerObject); mLocManager = null; Call this inside your onLocationChange Method when lat and long has been captured by the listener. It might take some time for the onLocationChange method to be called.

Which method is used to stop listening for updates in Android?

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

What is location listener?

android.location.LocationListener. Used for receiving notifications when the device location has changed. These methods are called when the listener has been registered with the LocationManager.

How do I stop Requestlocationupdates?

Use the expiration on your request, after that expirated time, the location services should quit automatically.


2 Answers

mLocManager.removeUpdates(locationListenerObject); mLocManager = null; 

Call this inside your onLocationChange Method when lat and long has been captured by the listener.

Hope I helped..

like image 123
Shah Avatar answered Sep 18 '22 18:09

Shah


You can stop the LocationListener by making its object to null after stoping LocationListener locationManager.removeUpdates(mLocListener);, that is mLocListener = null; when you want it to stop fetching the Latitudes and Longitudes.

like image 20
Lalit Poptani Avatar answered Sep 18 '22 18:09

Lalit Poptani