I created a new Android project on IntelliJ CE 2017.2 and got this error. I added the maven section as described in the answer.
When I run the default app that is created with the new project I get the error
Error while executing: am startservice com.test.myapp/com.android.tools.fd.runtime.InstantRunService
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.test.myapp/com.android.tools.fd.runtime.InstantRunService }
Error: app is in background uid null
I can still open the app manually on my phone and it works, but it doesn't start automatically and I get that error message.
I've seen this error using android api 26/27 (Oreo). In Oreo there are new background execution limits. tl;dr you should run services in the foreground.
to start your service using adb, use adb shell am start-foreground-service
instead of adb shell am startservice
.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
}
else {
context.startService(intent);
}
IMPORTANT After the service starts, Service.startForeground()
must be called within 5 seconds. The obvious place is within onCreate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With