I am using Service
Class on the Android O OS.
I plan to use the Service
in the background.
The Android documentation states that
If your app targets API level 26 or higher, the system imposes restrictions on using or creating background services unless the app itself is in the foreground. If an app needs to create a foreground service, the app should call
startForegroundService()
.
If you use startForegroundService()
, the Service
throws the following error.
Context.startForegroundService() did not then call
Service.startForeground()
What’s wrong with this?