Viktor Kinko

Android Jetpack WorkManager

The JetPack WorkManager's research purpose was to get familiar with it and understand its usage in production.
Viktor Kinko
Android Developer
WorkManager is a new approach to background tasks execution that is presented in androidx official library.
Characteristics
  • Depends on API it uses JobScheduler or AlarmManager in order to previous Android versions compatibility
  • Guarantee background tasks execution even if user closes app at all and reboots phone
  • Background task will be queued to be executed ASAP
  • Initial conditions can be set as following: charger connection, unlimited network or screen off
  • If task can't be executed asap (because of restrictions and reasons during the background task execution as well) it will be restarted. Restart is happening in a period of time that increasing each restart.
  • You can set recurrence interval for created tasks. Minimum time interval is 15 min
  • beginWith and then functions usage can help to make an execution chain for some tasks. Each block executes only after all the tasks were finished in previous, and you can set some tasks in one block. After one block is finished the next one gets combined results of the previous. The combination method can be set by setInputMerger.

The flowchart for background task execution organization mechanism was updated after Jetpack release in Guide to background processing section, the WorkManager was added. Android developers advice to use it in case of postponed task that not supposed to load data long.
But WorkManager is suitable for application logic organization (data sync, server messages or news checking, background data saving). Integrated checks for different system features, making WorkManager as instrument for application response on system conditions, are especially interesting as well as repetition possibility without server creation.
Thanks for reading!