7.0及以上版本应用被杀后重启服务
Restarting service when app is killed in 7.0 and above
直到 Android 6.0 每当我终止我的应用程序时,我的服务都会自动重新启动,但是当我在 7.1.1 中测试它时,我的服务不会重新启动,它会停止。
我试过像这样在 activity onDestroy 中重启服务,
@Override
protected void onDestroy() {
super.onDestroy();
Util.printMessage("onDestroy.....");
Intent locationIntent = new Intent(getApplicationContext(), SupportService.class);
startService(locationIntent);
Util.printMessage("running...?..." + isMyServiceRunning(SupportService.class));
}
但是这个解决方案没有用,任何人都可以建议是什么问题或如何再次启动服务,对于启动更改接收器我的广播在设备重新启动时没有收到调用。
将 onStartCommand()
的 return 类型更改为 START_STICKY
。如果服务被系统破坏,它将自动启动...有关 START_STICKY
Click
的更多信息
直到 Android 6.0 每当我终止我的应用程序时,我的服务都会自动重新启动,但是当我在 7.1.1 中测试它时,我的服务不会重新启动,它会停止。
我试过像这样在 activity onDestroy 中重启服务,
@Override
protected void onDestroy() {
super.onDestroy();
Util.printMessage("onDestroy.....");
Intent locationIntent = new Intent(getApplicationContext(), SupportService.class);
startService(locationIntent);
Util.printMessage("running...?..." + isMyServiceRunning(SupportService.class));
}
但是这个解决方案没有用,任何人都可以建议是什么问题或如何再次启动服务,对于启动更改接收器我的广播在设备重新启动时没有收到调用。
将 onStartCommand()
的 return 类型更改为 START_STICKY
。如果服务被系统破坏,它将自动启动...有关 START_STICKY
Click