Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access