From the course: Concurrent Programming with Android: Threads, Workers, and Kotlin Coroutines
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Set work request constraints
From the course: Concurrent Programming with Android: Threads, Workers, and Kotlin Coroutines
Set work request constraints
- [Narrator] When you create a work request, for the WorkManager API, you can apply constraints to your request. So that it's only executed when certain conditions apply. I'm going to demonstrate this using a virtual device rather than a physical device. Because I'm going to be showing what happens when you turn network functionality off. And on my physical device, that means you'd stop seeing my screen. I'll do the same thing though, using this virtual device and everything should work okay. You can follow along with the physical device though if you like. In my run code function, I'll create a new variable that I'll name constraints, and I'll create that object using constraints.builder. From there, I can call one of these set functions. I'm going to be using setRequiredNetworkType to make sure that my request is only executed when I have network connectivity. But there's also setRequiresBatteryNotLow,…
Contents
-
-
-
-
-
-
(Locked)
Run background tasks with IntentService5m 22s
-
(Locked)
Upgrade IntentService to JobIntentService4m 37s
-
(Locked)
Send results from JobIntentService to the UI7m 25s
-
(Locked)
Manage deferrable tasks with WorkManager5m 35s
-
(Locked)
Set work request constraints3m 9s
-
(Locked)
Get results from a background worker4m 56s
-
(Locked)
Send progress updates from a background worker5m 2s
-
(Locked)
-
-