Scheduling Work

To schedule a Worker to execute, you need a WorkRequest. The WorkRequest class itself is abstract, so you need to use one of its subclasses depending on the type of work you need to execute. If you have something that only needs to execute once, use a OneTimeWorkRequest. If your work is something that must execute periodically, use a PeriodicWorkRequest.

For now, you are going to use the OneTimeWorkRequest. This will let you learn more about creating and controlling the requests and verify that your PollWorker is functioning correctly. Later you will update your app to use a PeriodicWorkRequest.

Open PhotoGalleryFragment.kt, create a work request, and schedule it for execution.

Listing 22.3  Scheduling ...

Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.