android how to stop gps

后端 未结 5 1264
无人共我
无人共我 2020-12-10 06:55

After launching listener by the following code is working fine.

LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SERVICE)         


        
相关标签:
5条回答
  • 2020-12-10 07:17

    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 )
    
    0 讨论(0)
  • 2020-12-10 07:29

    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);
    
    0 讨论(0)
  • 2020-12-10 07:32

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

    0 讨论(0)
  • 2020-12-10 07:37

    If you are using maps, you have to do:

    locationManager.removeUpdates(locationListener);
    
    mMap.setMylocationEnabled(false);
    
    0 讨论(0)
  • 2020-12-10 07:41

    You could pass the parameter like this GPSLocationListener.this

    locationManager.removeGpsStatusListener(GPSLocationListener.this);
    

    the compile will not be wrong

    0 讨论(0)
提交回复
热议问题