Android 错误:应用程序位于后台uid null中

Android 错误:应用程序位于后台uid null中,android,intellij-idea,Android,Intellij Idea,我在IntelliJ 2017.2上创建了一个新的Android项目,并获得了成功。我添加了答案中描述的maven部分 当我运行使用新项目创建的默认应用程序时,我会收到错误消息 执行时出错:am startservice com.test.myapp/com.android.tools.fd.runtime.InstantRunService 启动服务:Intent{act=android.Intent.action.MAIN cat=[android.Intent.category.LAUNC

我在IntelliJ 2017.2上创建了一个新的Android项目,并获得了成功。我添加了答案中描述的maven部分

当我运行使用新项目创建的默认应用程序时,我会收到错误消息

执行时出错:am startservice com.test.myapp/com.android.tools.fd.runtime.InstantRunService

启动服务:Intent{act=android.Intent.action.MAIN cat=[android.Intent.category.LAUNCHER]cmp=com.test.myapp/com.android.tools.fd.runtime.InstantRunService}

错误:应用程序位于后台uid null中


我仍然可以在手机上手动打开应用程序,但它不会自动启动,我会收到错误消息。

我使用android api 26/27(Oreo)看到了这个错误。在奥利奥有新的。tl;dr您应该在前台运行服务

要使用adb启动您的服务,请使用adb shell am start前台服务

与adb壳牌am startservice相比,Oreo(26+)需要前台服务
重要信息服务启动后,必须在5秒内调用
service.startForeground()
。最明显的地方是
onCreate

如何在IntelliJ中更改它?我只能设置启动标志,但不能更改命令!?作为一种解决方法,您可以禁用即时运行。转到设置->构建、执行、部署->即时运行。取消选中“在部署时启用即时运行到热插拔代码/资源更改(默认启用)”@shadanan此选项有效。我不再收到错误,应用程序会自动启动。如果你把这个作为答案贴出来,我会把它标记为正确答案。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    context.startForegroundService(intent);
}
else {
    context.startService(intent);
}