本文介绍了Android WorkManager 与 JobScheduler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要新的 Android WorkManager 如果我们已经一个JobScheduler 以及一些漂亮的反向移植(AndroidJobFirebaseJobDispatcher) 具有相同的功能?它有什么杀手级功能吗?因为我没有看到任何让我想要迁移到又一个调度程序的东西.

解决方案

WorkManager 有很多不错的功能,但它的主要目标是在旧设备上使用 JobScheduler 的 API"...等等,但我们已经有一些向后移植.他们怎么了?简而言之:

  1. FireaseJobDispatcher 很好,但它需要 Google Play 来安排工作,例如,如果我们的目标是中国,那么这并不好.

  2. Evernote 的 AndroidJob 是一个具有很多功能的优秀反向移植.恕我直言,它安排任何工作的最佳选择.但是现在最新版本的库在后台使用了前面提到的 WorkManager.而且,不幸的是,迟早该库将被弃用:

如果你开始一个新项目,你应该使用 WorkManager 而不是这个库.您还应该开始将您的代码从这个库迁移到 WorkManager.在未来的某个时候,该库将被弃用.

他们建议改用 WorkManager,因为它提供了更多功能,并且还给了我们一个简短的比较:

|特色 |android-job |工作经理 ||------------------ |----------- |----------- ||确切的工作 |是 |没有 ||临时工作|是 |没有 ||日常工作 |是 |没有 ||自定义记录器 |是 |没有 ||观察工作状态 |没有 |是 ||连锁工作 |没有 |是 ||工作序列 |没有 |是 |

Imo,最后 3 个功能非常有用并且仅由 WorkManager 支持.所以我最后一个问题的答案是肯定的,它确实有一些杀手级功能:

  • 不需要 Google Play
  • 可查询
  • 可链接
  • 机会主义

要了解有关 WorkManager 的更多信息,请务必观看 Sumir Kataria 的本次演讲>

附言如果有人知道为什么 FirebaseJobDispatcher 受到 Google 工程师的积极支持 而不是被弃用写在下面的评论:)

Why do we need the new Android WorkManager if we already have a JobScheduler along with a few nifty backports (AndroidJob and FirebaseJobDispatcher) with the same functionality? Does it have any killer-features or something? Because I don't see anything that makes me want to migrate to the yet another scheduler.

解决方案

"WorkManager has a lot of nice features but its main goal is to use the JobScheduler's API on older devices"... Wait, but we already have some backports. What's wrong with them? To cut it short:

  1. FireaseJobDispatcher is fine but it requires Google Play to schedule jobs which isn't good if we're targeting China, for example.

  2. Evernote's AndroidJob is an excellent backport with a lot of functionality. Imho, it was the best choice for scheduling any work. But now the latest version of the library uses the aforementioned WorkManager under the hood. And, unfortunately, sooner or later the library will be deprecated:

They suggest to switch to the WorkManager because it provides more features and they also give us a short comparison:

|   Feature          | android-job | WorkManager |
| ------------------ | ----------- | ----------- |
| Exact jobs         | Yes         | No          |
| Transient jobs     | Yes         | No          |
| Daily jobs         | Yes         | No          |
| Custom Logger      | Yes         | No          |
| Observe job status | No          | Yes         |
| Chained jobs       | No          | Yes         |
| Work sequences     | No          | Yes         |

Imo, the the last 3 features are very useful and supported only by the WorkManager. So the answer to my last question is yes, it does have some killer-features:

  • No Google Play required
  • Queryable
  • Chainable
  • Opportunistic

To learn more about WorkManager one should definitely watch this talk by Sumir Kataria

P.S. If anyone knows why FirebaseJobDispatcher is actively supported by Google engineers instead of being deprecated write in the comments below :)

这篇关于Android WorkManager 与 JobScheduler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 22:25