开发者

android how to stop gps

After launching listener by the following code is working fine.

LocationManager locationManager =(LocationManager) getSystemService(Context.LOCATION_SE开发者_StackOverflow中文版RVICE);
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 ?


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);


If you are using maps, you have to do:

locationManager.removeUpdates(locationListener);

mMap.setMylocationEnabled(false);


You could pass the parameter like this GPSLocationListener.this

locationManager.removeGpsStatusListener(GPSLocationListener.this);

the compile will not be wrong


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 )


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜