android - 从 LocationManager 取消订阅 LocationListener

标签 android locationmanager locationlistener

如何取消订阅 LocationListenerLocationManager 接收更新?

我是这样设置的

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/

相关文章:

android - onLocationChanged 总是返回我的旧位置

android - requestLocationUpdates 花费的时间太长

java - 无法更新纬度和经度

android - 完全停止或重新启动 Android 应用程序中的所有 Activity 以反射(reflect)新的语言选择

适用于所有服务的 Android 位置监听器

android - 应用程序未打开或关闭时的后台服务

Android 位置 : PendingIntent vs. LocationListener

android - 如何在TextView中显示带有css样式表的html?

java - 启动画面后的 Activity

android - 带 fragment 的垂直 ViewPager