@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
if(intent == null)
return;
}
@Override
public void onDestroy() {
super.onDestroy();
Intent intent = new Intent(SensorService.this, SensorService.class);
startService(intent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// flags = Service.START_STICKY;
flags = Service.START_REDELIVER_INTENT;
return super.onStartCommand(intent, flags, startId);
}
PS:重点就在这个 flags ,开始时用Service.START_STICKY; Service 经常会自动FC查了好久才发现再次自启动时候onStart里intent为null,改为flags = Service.START_REDELIVER_INTENT;就可以了。