gpt4 book ai didi

android - 奥利奥 : Does JobService not require startForeground?

转载 作者:行者123 更新时间:2023-12-05 00:21:02 28 4
gpt4 key购买 nike

作为测试,我从我们拥有的工作服务中删除了“startForeground(通知)”,它似乎仍在工作。

我们是否不需要在 Android O 及更高版本上发布工作服务的前台通知?

我无法找到这方面的具体文档。
任何引用都会很棒。

太感谢了

编辑

对于那些有同样问题的人,我已经在生产环境中测试了几天。我们的应用程序有一个持续的通知,我一直在从作业服务启动/更新它,而没有调用 startForeground,并且在 crashlytics 中没有看到任何安全异常。我有信心说:

对于短期运行的任务,您不需要从作业服务调用 startForeground (异常(exception)情况很可能适用于正在进行的任务。我的代码只是进行 api 调用并更新通知 View )

感谢 0X0nosugar 和 WasabiTea

最佳答案

To lower the chance of these problems, Android 8.0 places limitations on what apps can do while users aren't directly interacting with them. Apps are restricted in two ways:

  • Background Service Limitations: While an app is idle, there are limits to its use of background services. This does not apply to foreground services, which are more noticeable to the user.

  • Broadcast Limitations: With limited exceptions, apps cannot use their manifest to register for implicit broadcasts. They can still register for these broadcasts at runtime, and they can use the manifest to register for explicit broadcasts targeted specifically at their app.

In most cases, apps can work around these limitations by using JobScheduler jobs. This approach lets an app arrange to perform work when the app isn't actively running, but still gives the system the leeway to schedule these jobs in a way that doesn't affect the user experience. Android 8.0 offers several improvements to JobScheduler that make it easier to replace services and broadcast receivers with scheduled jobs; for more information, see JobScheduler improvements.



原始文档在这里 - https://developer.android.com/about/versions/oreo/background

希望这可以帮到你

关于android - 奥利奥 : Does JobService not require startForeground?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53786042/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com