I am using Service
Class on the Android O OS.
I plan to use the Service
in the background.
The Android recommendation states that startService should use startForegroundService.
If you use startForegroundService, the Service
throws a Context.startForegroundService()
did not then call Service.startForeground()
error.
What's wrong with this?
Just a heads up as I wasted way too many hours on this. I kept getting this exception even though I was calling
startForeground(..)
as the first thing inonCreate(..)
. In the end I found that the problem was caused by usingNOTIFICATION_ID = 0
. Using any other value seems to fix this.I have researched on this for a couple of days and got the solution. Now in Android O you can set the background limitation as below
The service which is calling a service class
and the service class should be like