Work Manager

What is WorkManager?

WorkManager is one of the Android Architecture Component and part of Android Jetpack. WorkManager is an Android library that runs deferrable background work when the work’s constraints are satisfied. WorkManager allows you to schedule work to run one- time or repeatedly using flexible scheduling windows.

How to use WorkManager?

Step 1:

In Build.gradle

Add the dependency of workmanager in your app build.gradle implementation “androidx.work:work-runtime:$work_version”

Step 2:

Create a Worker class

Step 3:

Create a Work Request

  1. Create a work constraints object because constraints ensure that work is deferred until optimal conditions are met means work manager will work until when the specified condition will available.

  1. Schedule a one time task

  1. Schedule a periodic task

  1. If you want to pass the data

 

Leave a Reply