Periodic Tasks with Android WorkManager

Ikhiloya Imokhai
The Startup
Published in
7 min readOct 22, 2019

--

source: Android Developers Blog

WorkManager is an Android Jetpack library that runs deferrable, guaranteed background work when the work’s constraints are satisfied even if the app exits.

A deferrable task is one that doesn’t need to be executed immediately and may depend upon some constraints such as network conditions, storage space, and charging status.

WorkManager has support for both asynchronous one-off and periodic tasks.

For a one-off task, a OneTimeWorkRequest is used, that is, a WorkRequest that will only execute once.

Alternatively, for recurring or tasks that should be run periodically, a PeriodicWorkRequest is used to execute such tasks. For example, you may want to periodically backup your data, download fresh content in your app, or upload logs to a server.

PeriodicWorkRequest cannot be chained. If your task requires chaining of dependent tasks, consider OneTimeWorkRequest.

Furthermore, you can also easily define retry strategies if your work is stopped and you want to retry it later.

If you are new to WorkManager, consider the following articles:

--

--

Ikhiloya Imokhai
The Startup

Software Developer | imokhaiikhiloya@gmail.com | https://github.com/Ikhiloya | Reach out to me for Android/Java/Technical writing projects.