如何防止Service被杀(被杀后立即重启),类似于手机助手之类的服务,但是如果是手动停止的话则服务停止
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
flags = START_STICKY;
return super.onStartCommand(intent, flags, startId);
}
还有一种方法,在Service的onDestory方法中重启服务,不推荐
@Override
public void onDestroy() {
startService();
super.onDestroy();
}