0

我有一个实现 LocationListener 的前台服务。当服务被杀死时,它会继续得到修复。然而,这就是我在onDestroy()

@Override
public void onDestroy() {
    Log.e(getPackageName(), "Destroying GPSservice");
    super.onDestroy();
    running = false;
    stopForeground(true);
    locationManager.removeUpdates(EventService.this);
    locationManager = null;
}

有什么我想念的吗?

编辑

更多代码。这是在onCreate()

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    String bestProvider = locationManager.getBestProvider(criteria, true);

    Location location = locationManager.getLastKnownLocation(bestProvider);
    if (location != null) {
        onLocationChanged(location);
    }
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
            3000L, 15.0f, this);
4

2 回答 2

1

利用

locationManager.removeUpdates(Your_Location_Listener_instance);

代替

locationManager.removeUpdates(EventService.this);

有关更多信息,请参阅 doc public void removeUpdates (LocationListener listener)

于 2012-06-20T15:16:06.233 回答
0

我已经解决了这个问题。事实证明,MyLocationOverlay也绑定到 LocationSensorThread,而我从未将其关闭。所以这让 GPS 保持清醒。

于 2012-07-06T07:37:59.667 回答