0

我有一个mapView已注册的活动,LocationListener每两秒检查一次新位置。当我按下返回按钮返回应用程序的主屏幕时,GPS 会继续每两秒检查一次位置。停止时听众不会Activity停止吗?如果不是,我该如何处理?我目前还没有覆盖onStop().

private final LocationListener locationListener = new LocationListener() {
    public void onLocationChanged(Location location) {
        updateWithNewLocation(location);
    }

    public void onProviderDisabled(String provider) {
        //TODO do something to handle when the provider is disabled
    }

    public void onProviderEnabled(String provider) { }
    public void onStatusChanged(String provider, int status, Bundle extras) { }
};
4

1 回答 1

3

您需要覆盖您的onPause方法,Activity因为它肯定会被调用。在该onPause方法中,您应该取消注册LocationListener.

你通过

locationManager.removeUpdates(yourListener);

如果你有,mapView我有时会在locationOverlay保持听众注册和使用 GPS 时遇到问题,即使 mapview 在后台也是如此。

于 2010-08-16T09:40:56.167 回答