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.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
In my testing, JobScheduler could continue running a service after the user closes my app but I could find no way to do that with WorkManager.
I tested on a Nexus 5X running Oreo Android 8.0.0 (API 26). I may have just gotten lucky that this device/OS combination could continue the service after killing the app. I believe it might be device specific because of what I read in this answer https://stackoverflow.com/a/52605503/2848676 to Android. Is WorkManager running when app is closed?. "You can find a complete list of different OEM behaviors on dontkillmyapp.com."
NOTE: I observed that when the user closed the app, it took several seconds or even minutes for the JobService to restart.
To make JobScheduler launch a service that survives app death, created the service as follows:
ScannerAsJobService
updates a notification with current information, including whether the service is "in the background" (which I quote because there are different definitions of "background" but this one accurately reflected whether the app was no longer running):WorkManager sits on top of JobScheduler and AlarmManager. WorkManager picks the right APIs to use, based on conditions like the user's device API level
WorkManager is a simple, but incredibly flexible library that has many additional benefits. These include:
"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:
FireaseJobDispatcher is fine but it requires Google Play to schedule jobs which isn't good if we're targeting China, for example.
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:
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:
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 :)
WorkManager just seems like Google's answer to Evernote's Android-Job library, but with a few improvements. It uses JobScheduler, Firebase JobDispatcher and AlarmManager just like Android-Job depending on the device's API level. Their usage of tags looks pretty much the same and assigning constraints to jobs/work are similar enough.
The two features that I am excited about are: being able to chain work and the ability to be opportunistic on work with constraints. The first will allow work (jobs) to be broken up and more modular for me. And with more modular work, each piece of work may have fewer constraints improving the chance they will complete earlier (opportunistic). For example, the majority of processing work can complete before the work with a network constraint needs to be met.
So if you're happy with your current scheduler implementation and the two features I mentioned don't add value, I don't see a huge benefit to making the switch just yet. But if you're writing something new, it'll probably be worth it to use WorkManager.
WorkManager
usesJobScheduler
service to schedule the jobs. IfJobScheduler
is not supported by the device, then it uses FirebaseJobDispatcher
service. If FirebaseJobDispatcher
is not available on the device, it will useAlarmManager
andBroadcastReceiver
.So with
WorkManager
, you don't need to worry about backward compatibility. In addition to this, it allows for defining constraints, which need to be met in order for the job to be run, such as defining network constraints, battery level, charging state and storage level.It allows task chaining and passing of argument to the job.
http://www.zoftino.com/scheduling-tasks-with-workmanager-in-android