如何取消订阅从LocationManager接收更新的LocationListener
下面是我设置它的方法
mLocationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
mListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.i("LocationListener", "Logging Change");
}
}
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
5000, 1, mListener);退出创建LocationListener的视图后,LogCat窗口中仍显示日志消息。
我知道这是因为我孤立了侦听器,但是我在LocationListener上看不到任何销毁方法,在LocationManager对象上也看不到任何“移除侦听器”风格的方法。
发布于 2010-01-20 06:10:54
在LocationManager上调用removeUpdates,传递您的位置侦听器。
发布于 2010-01-20 06:11:32
mLocationManager.removeUpdates(mListener);发布于 2010-01-20 06:11:26
我觉得removeUpdates应该帮上忙。
mLocationManager.removeUpdates(mListener)https://stackoverflow.com/questions/2097473
复制相似问题