Stop Location Listener in Android

31,359

Solution 1

mLocManager.removeUpdates(locationListenerObject);
mLocManager = null;

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

Hope I helped..

Solution 2

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.

Share:
31,359

Related videos on Youtube

Chrishan
Author by

Chrishan

Experienced Android Developer. Please find my profile at LinkedIn

Updated on July 09, 2022

Comments

  • Chrishan
    Chrishan almost 2 years

    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 !

    • PravinCG
      PravinCG almost 13 years
      removeUpdates is the way to go, can you show some code as to why it did not work.
  • AbhishekB
    AbhishekB over 10 years
    It might take some time for the onLocationChange method to be called. Around 1 sec might be. Right?
  • rockhammer
    rockhammer over 7 years
    thx this works. the weird thing is that the .removeUpdates() wants us to ask for permissions!
  • rockhammer
    rockhammer over 7 years
    I just tried this on a actual device and it does not remove the listening for updates
  • Ruchir Baronia
    Ruchir Baronia almost 7 years
    Out of curiosity, why is setting the listener to null necessary if we already called removeUpdates(locationListener l)?