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リスナー)を参照してください。

于 2012-06-20T15:16:06.233 に答える
0

私は問題を解決しました。結局のところMyLocationOverlay、LocationSensorThreadにもバインドされており、私はそれをオフにすることはありませんでした。つまり、GPSを目覚めさせていました。

于 2012-07-06T07:37:59.667 に答える