7

After launching listener by the following code is working fine.

LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
                    LocationManager.GPS_PROVIDER, WLConstants.DELAY_HOUR, gpsl
                            .getMinDistance(), gpsl);

After some time i stop the listener by the following code

locationManager.removeUpdates(this);

but problem is it still searching my gps any solution ??? how to stop gps ?

d-man
  • 57,473
  • 85
  • 212
  • 296
  • 2
    Remember to accept answers to previous questions you have asked -- you're only at 45% acceptance so far. That way more people will be likely to continue answering questions. :) – Christopher Orr Jan 06 '10 at 14:51

5 Answers5

19

You need to pass the same object implementing LocationListener that you requested location updates for to the locationManager.removeUpdates() method.

So in unless this and gpsl are one and the same, you should call:

locationManager.removeUpdates(gpsl);
Jeff Gilfelt
  • 26,131
  • 7
  • 48
  • 47
3

If you are using maps, you have to do:

locationManager.removeUpdates(locationListener);

mMap.setMylocationEnabled(false);
Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
1

You could pass the parameter like this GPSLocationListener.this

locationManager.removeGpsStatusListener(GPSLocationListener.this);

the compile will not be wrong

Romain Francois
  • 17,432
  • 3
  • 51
  • 77
0

My listener implemention

public class GPSLocationListener extends Activity implements LocationListener {

    @Override
        public void onLocationChanged(Location location) {
//code here
    }

    }

when i try to remove listener using follwing code compile time error.

locationManager.removeGpsStatusListener(GPSLocationListener )
d-man
  • 57,473
  • 85
  • 212
  • 296
  • 2
    You need to use the *instance* name rather than the *class* name when removing the listener. In your original question, your listener is a variable called `gpsl`. Presumably, this is a member variable in your class. If not, make it a member variable instead of local to that method. Then you can pass `gpsl` when you call `removeGpsStatusListener`. – Christopher Orr Jan 06 '10 at 14:50
  • 1
    You can't use removeGpsStatusListener with a LocationListener! A LocationListener is different from a GpsStatus.Listener. – Erwan May 29 '13 at 02:51
0

You have to pass the instance to your GPSLocationListener go the removeGpsStatusListener method and not the class name.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Stelian Iancu
  • 2,462
  • 3
  • 18
  • 28