我有一个实现 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);