在 Android 6.0 之前,每当我终止我的应用程序时,我的服务都会自动重启,但是当我在 7.1.1 中测试它时,我的服务不会重启,它会停止。
我试过像这样在 onDestroy Activity 中重启服务,
@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()
的返回类型更改为 START_STICKY
。如果服务被系统破坏,它将自动启动...有关 START_STICKY
的更多信息 Click
关于android - 7.0及以上版本应用被杀后重启服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51023839/