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

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