A sample application to demonstrate usage of Workmanager
WorkManager
is an API that makes it easy to schedule reliable, asynchronous tasks that are expected to run even if the app exits or the device restarts. The WorkManager
API is a suitable and recommended replacement for all previous Android background scheduling APIs, including FirebaseJobDispatcher
, GcmNetworkManager
, and Job Scheduler
. WorkManager
incorporates the features of its predecessors in a modern, consistent API that works back to API level 14 while also being conscious of battery life.
Declaratively define the optimal conditions for your work to run using Work Constraints. (For example, run only when the device is on Wi-Fi, when the device is idle, or when it has sufficient storage space, etc.)
WorkManager
allows you to schedule work to run one- time or repeatedly using flexible scheduling windows. Work can be tagged and named as well, allowing you to schedule unique, replaceable work and monitor or cancel groups of work together. Scheduled work is stored in an internally managed SQLite
database and WorkManager takes care of ensuring that this work persists and is rescheduled across device reboots. In addition, WorkManager adheres to power-saving features and best practices like Doze
mode, so you don’t have to worry about it.
Sometimes work fails. WorkManager
offers flexible retry policies, including a configurable exponential backoff policy.
For complex related work, chain individual work tasks together using a fluent, natural, interface that allows you to control which pieces run sequentially and which run in parallel.
The sample app shows how to perform a background task using WorkManager
by blurring an image from Media folder.
- Ask for Read/Write Permission on Device images.
- Select image from Media folder.
- Apply Blur amount (litte, more, most) by choosing options.
- Send Status
Notification
when theworkmanager
starts working. WorkManager
Periodic request like Clean Up Worker-> Blur Image Worker-> Save Image Worker.WorkManager
custom configuration.- Publish progress from your Worker.
- Display work progress in the UI.
- Save Image in a specified folder & allow users to see the resulted image after the blur operation.
- Write instrumentation tests for your Workers.
Select Image | Blur Image | Result |
---|---|---|