Android how to stop gps

After starting the listener using the following code, it works fine.

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

After a while I will stop the listener using the following code

 locationManager.removeUpdates(this); 

but the problem is that he is still looking for my gps any solution ??? how to stop gps?

+7
android gps
source share
5 answers

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

Thus, if this and gpsl do not match, you should call:

 locationManager.removeUpdates(gpsl); 
+19
source share

If you use cards, you need to do:

 locationManager.removeUpdates(locationListener); mMap.setMylocationEnabled(false); 
+3
source share

You can pass a parameter similar to this GPSLocationListener.this

 locationManager.removeGpsStatusListener(GPSLocationListener.this); 

compilation will not be erroneous

+1
source share

Implementation of my listener

 public class GPSLocationListener extends Activity implements LocationListener { @Override public void onLocationChanged(Location location) { //code here } } 

when I try to remove the listener using a code compile-time error.

 locationManager.removeGpsStatusListener(GPSLocationListener ) 
0
source share

You need to pass the instance to your GPSLocationListener method removeGpsStatusListener , not the class name.

0
source share

All Articles