Creating a Worker

The Worker class is where you will put the logic you want to perform in the background. Once your worker is in place, you will create a WorkRequest that tells the system when you would like your work to execute.

Before you can add your worker, you first need to add the appropriate dependency in your app/build.gradle file.

Listing 27.1  Adding the WorkManager dependency (app/build.gradle)

dependencies {
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation ""

Sync the project to download the dependency.

With your new library in place, move on to creating your Worker. Create a new class called PollWorker that extends the Worker base class. ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.