0

I am trying to launch a service on startup. It uses a broadcast receiver that calls startservice that shows a notification to keep a foreground service running.

The service is listed in the manifest as well as the receiver.

The application actually works great on a test device running kit kat. When i tried it on later android versions the service doesnt start on startup. I am able to open my app and then call startservice in my app so the service is fine. If i go to the broadcast receiver and start an intent to start main activity and the app runs on device startup.

If i look at the logcat on startup it says "cannot start service app in background".

Can anyone help me understand what is actually happening on startup?

Clinton
  • 347
  • 1
  • 2
  • 14
  • 2
    Scan Logcat for relevant system messages. Note that on Android 8.0+, you need to call `startForegroundService()` to start a service from a `BroadcastReceiver`. – CommonsWare Apr 12 '20 at 14:59
  • Spot on. Adding the version check to the receiver so that it calls startforegroundservice on later versions. It seems like quite a bit changed with oreo. – Clinton Apr 12 '20 at 15:08

0 Answers0