代码之家  ›  专栏  ›  技术社区  ›  Greg B

从locationManager取消订阅locationListener

  •  5
  • Greg B  · 技术社区  · 15 年前

    如何取消订阅 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);
    

    在我退出创建 位置侦听器 我还在logcat窗口中收到日志消息。

    我理解这是因为我孤立了听众,但我看不到 位置侦听器 我也看不到 位置管理器 对象。

    3 回复  |  直到 15 年前
        1
  •  14
  •   Mark B    15 年前

    呼叫 removeUpdates 在locationmanager上,传递位置侦听器。

        2
  •  6
  •   Chiwai Chan    15 年前
    mLocationManager.removeUpdates(mListener);
    
        3
  •  3
  •   Sam DeHaan    13 年前

    我想 removeUpdates 应该帮助。

    mLocationManager.removeUpdates(mListener)