RemoteServiceException Context.startForegroundService () then did not call Service.startForeground ()

enter image description here

I got this error report through Fabric.io in both Android 8.0 and Android 7.x.

Since these are not only certain classes that fail, I don’t know how to handle them.

Please help me if you have any ideas.

+7
source share
1 answer

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.

+5
source

Source: https://habr.com/ru/post/1272057/


All Articles