然后,RemoteServiceException Context.startForegroundService()并未调用Service.startForeground() [英] RemoteServiceException Context.startForegroundService() did not then call Service.startForeground()

查看:75
本文介绍了然后,RemoteServiceException Context.startForegroundService()并未调用Service.startForeground()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android 8.0和Android 7.x中都通过Fabric.io收到了此错误报告.

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.

推荐答案

在Android O中,我们有一个新的背景限制.当您尝试启动startService()时,将获得IlleagalStateException,因此现在您应该使用startForegroundService(),但是如果通过此新方法启动服务,则会在屏幕截图中看到类似的错误.为避免发生此异常,您需要在startForegroundService()之后创建startForeground()5秒钟,以通知用户您正在后台工作.

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.

因此,Android O中只有一种方法:

So, where is only one way in Android O:

context.startForegroundService(intent)

在使用中,onCreate()会这样:

And in service onCreate() make something like that:

startForeground(1, new Notification());

更新 因此,正如我所假设的那样,一些制造商已经在Android N上移植了这些新的背景限制,这就是为什么您可以在Android N上获得相同异常的原因.

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.

这篇关于然后,RemoteServiceException Context.startForegroundService()并未调用Service.startForeground()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆