如何取消订阅 LocationListener
从 LocationManager
接收更新?
我是这样设置的
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
的 View 后,我仍然在 LogCat 窗口中收到日志消息。
我知道这是因为我正在孤立监听器,但我在 LocationListener
上看不到任何销毁方法,在 LocationManager上也看不到任何“删除监听器”样式的方法
对象。
最佳答案
调用removeUpdates在 LocationManager 上,传递您的位置监听器。
关于android - 从 LocationManager 取消订阅 LocationListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2097473/