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);