In Android O, we have new background restrictions. When you try to start the service (), you will get an IlleagalStateException, so now you should use startForegroundService (), but if you start using this new method, you will get an error, as in the screenshot. To avoid this exception, you have 5 seconds to do startForeground () after startForegroundService () to notify the user that you are running in the background.
So where is only one way in Android O:
context.startForegroundService(intent)
And in the onCreate () service, do something like this:
startForeground(1, new Notification());
UPDATE So, as I suppose, some manufacturers have backport on Android N these new background restrictions, so you can get the same exception in Android N.
source share