Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working with WorkManager

Working with WorkManager

This talk is about opportunistic guaranteed deferred background execution on Android. I'm not kidding. This is what WorkManager handles for us. You'll get a grasp on the basic concepts of WorkManager and by the time you're done with the slides, you'll be able to start Working with WorkManager!

Presented at the January 2020 installment of the Android Budapest meetup at AutSoft Ltd.

The talk was recorded and it's available on the Android Budapest YT channel:
https://www.youtube.com/watch?v=oh9AgdV5KbQ

E8168a08862631072b2e82e7b662dc07?s=128

István Juhos

January 30, 2020
Tweet

More Decks by István Juhos

Other Decks in Programming

Transcript

  1. István Juhos juhos.istvan@autsoft.hu stewemetal Working with WorkManager

  2. @stewemetal Execution Opportunistic Guaranteed Background Deferred

  3. @stewemetal Opportunistic

  4. @stewemetal Guaranteed Opportunistic

  5. @stewemetal Deferred Opportunistic Guaranteed

  6. @stewemetal Background Opportunistic Guaranteed Deferred

  7. @stewemetal Execution Opportunistic Guaranteed Background Deferred

  8. @stewemetal Just think about it… E x e c u

    t i o n O p p o r t u n i s t i c G u a r a n t e e d B a c k g r o u n d D e f e r r e d
  9. @stewemetal How to handle such works? Schedule one-time and periodic

    works
  10. @stewemetal How to handle such works? Remember work parameters

  11. @stewemetal How to handle such works? Listen for system-wide state

    changes
  12. @stewemetal How to handle such works? Respect background processing limits

  13. @stewemetal How to handle such works? Monitor the state of

    existing works
  14. @stewemetal How to handle such works? Cancel works

  15. @stewemetal How to handle such works? Reschedule failed works

  16. @stewemetal How to handle such works? Coroutine and Rx support

  17. @stewemetal How to handle such works? Testing support

  18. @stewemetal How to handle such works?

  19. @stewemetal How to handle such works?

  20. @stewemetal How to handle such works? WorkManager

  21. @stewemetal Let’s get to Work!

  22. @stewemetal Let’s get to Work! https://developer.android.com/jetpack/androidx/releases/work#declaring_dependencies

  23. @stewemetal Defining a Work

  24. @stewemetal Defining a Work

  25. @stewemetal Defining a Work

  26. @stewemetal Defining a Work

  27. @stewemetal Defining a Work

  28. @stewemetal Defining a Work

  29. @stewemetal Defining a Work

  30. @stewemetal Defining a Work

  31. @stewemetal Defining a Work with Coroutines

  32. @stewemetal Defining a Work with Coroutines

  33. @stewemetal Defining a Work with Coroutines

  34. @stewemetal Defining a Work with Coroutines

  35. @stewemetal Defining a Work with Rx

  36. @stewemetal Defining a Work with Rx

  37. @stewemetal Defining a Work with Rx

  38. @stewemetal Constraints

  39. @stewemetal Constraints

  40. @stewemetal Constraints

  41. @stewemetal Constraints

  42. @stewemetal Constraints

  43. @stewemetal Constraints

  44. @stewemetal Constraints

  45. @stewemetal Constraints

  46. @stewemetal Constraints

  47. @stewemetal Constraints

  48. @stewemetal Constraints

  49. @stewemetal Constraints

  50. @stewemetal Constraints

  51. @stewemetal Defining One-​Time Work​s

  52. @stewemetal One​Time​WorkRequest

  53. @stewemetal OneTimeWorkRequest

  54. @stewemetal OneTimeWorkRequest

  55. @stewemetal OneTimeWorkRequest

  56. @stewemetal OneTimeWorkRequest

  57. @stewemetal OneTimeWorkRequest

  58. @stewemetal OneTimeWorkRequest

  59. @stewemetal OneTimeWorkRequest

  60. @stewemetal OneTimeWorkRequest

  61. @stewemetal OneTimeWorkRequest

  62. @stewemetal OneTimeWorkRequest

  63. @stewemetal OneTimeWorkRequest

  64. @stewemetal OneTimeWorkRequest

  65. @stewemetal OneTimeWorkRequest

  66. @stewemetal OneTimeWorkRequest

  67. @stewemetal OneTimeWorkRequest

  68. @stewemetal Enqueueing One-Time Works

  69. @stewemetal Enqueueing One-Time Works

  70. @stewemetal Enqueueing One-Time Works

  71. @stewemetal Enqueueing One-Time Works uniqueWorkName =

  72. @stewemetal Enqueueing One-Time Works

  73. @stewemetal Enqueueing One-Time Works

  74. @stewemetal Enqueueing One-Time Works

  75. @stewemetal Enqueueing One-Time Works

  76. @stewemetal Defining Periodic Works

  77. @stewemetal OneTimeWorkRequest

  78. @stewemetal PeriodicWorkRequest

  79. @stewemetal PeriodicWorkRequest

  80. @stewemetal PeriodicWorkRequest

  81. @stewemetal PeriodicWorkRequest

  82. @stewemetal PeriodicWorkRequest

  83. @stewemetal PeriodicWorkRequest

  84. @stewemetal PeriodicWorkRequest

  85. @stewemetal PeriodicWorkRequest

  86. @stewemetal Enqueueing Periodic Works

  87. @stewemetal Enqueueing Periodic Works

  88. @stewemetal Enqueueing Periodic Works

  89. @stewemetal Enqueueing Periodic Works

  90. @stewemetal Enqueueing Periodic Works

  91. @stewemetal Monitoring Existing Works

  92. @stewemetal Monitoring Existing Works

  93. @stewemetal Monitoring Existing Works - WorkInfo

  94. @stewemetal Monitoring Existing Works - WorkInfo

  95. @stewemetal Monitoring Existing Works - WorkInfo

  96. @stewemetal Cancelling Works

  97. @stewemetal Cancelling Works

  98. @stewemetal Cancelling Works

  99. @stewemetal Cancelling Works

  100. @stewemetal Chains

  101. @stewemetal

  102. None
  103. None
  104. https://developer.android.com/guide/background/

  105. @stewemetal References • The official documentation of WorkManager https://developer.android.com/topic/libraries/architecture/workmanager •

    The official documentation for testing WorkManager https://developer.android.com/topic/libraries/architecture/workmanager/h ow-to/testing-210 • Background Work with WorkManager – Kotlin codelab https://codelabs.developers.google.com/codelabs/android-workmanager- kt/index.html
  106. @stewemetal References • Android Jetpack: easy background processing with WorkManager

    (Google I/O ‘18) https://www.youtube.com/watch?v=IrKoBFLwTN0 • WorkManager: Beyond the Basics (Android Dev Summit ‘19) https://www.youtube.com/watch?v=Bz0z694SrEE • When WorkManager Stops Working (Dan Lew) https://blog.danlew.net/2020/01/07/when-workmanager-stops-working/
  107. István Juhos juhos.istvan@autsoft.hu stewemetal Working withWorkManager • Use it when

    your work • depends on system or resource state AND • doesn’t need precise timing • Respects background processing limits • Highly configurable, supports Coroutines and Rx