Reputation: 415
I received this error report through Fabric.io in both Android 8.0 and Android 7.x.
Since it's not just specific classes that fail, I do not know how to handle them.
Please help me if you have any ideas.
Upvotes: 11
Views: 14303
Reputation: 1746
In Android O, we have a new background limitations. When you're trying to startService(), you will get IlleagalStateException, so now you should use startForegroundService(), but if you start service by this new method, you will get error like on your screenshot. To avoid this exception you have 5 seconds to make startForeground() after startForegroundService(), to notify user, that you're working in background.
So, where is only one way in Android O:
context.startForegroundService(intent)
And in service onCreate() make something like that:
startForeground(1, new Notification());
UPDATE So as i assume, some manufacturers have backport on Android N these new background limitations, that's why you can get same exception in Android N.
Upvotes: 7