Introduction to WorkManager implementation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in the previous video you learned about the advantages of using word manager in this video you'll see the code needed to create an nqa task let's take a look at three important classes that you need to know to use work manager in your app worker work request and work manager let's begin with the worker class your worker implementations need to extend the worker class and overwrite its new word method to define what your task does work major uses this function to execute your task asynchronously in the background thread next you need to create a work request that represents a request to perform the task the work request also allows you to specify constraints over this task such as run this task only while the phone is charging or when the device is connected to wi-fi you can also use work requests to specify the frequency that you want to run your tasks such as once or periodically finally the manager class takes all the work constraints into consideration and runs your task when these conditions are met workmanager also allows you to create a chain of multiple workers this functionality is particularly handy when you want to run several tasks simultaneously or in a particular order let's say you want to apply multiple filters on a particular image when that's complete compress the image and finally upload the compressed image to a server if we translate this to a word manager worker tree the app needs to cue three image filter workers to run in parallel the output of these workers are then passed to a compressed worker once the compressed worker completes the output is passed into the upload worker which uploads the image to a remote server notice there is battery constraint on the filter image workers storage constraint on the compressed worker and network constraint on the upload worker work manager will check if these constraints are met before running the associated worker now let's see how this translates into called your code will look something like this once you create the workers and work requests with the desired constraints to start queueing your workers get an instance of work manager call begin with function passing in the image filter workers as a list so they will be executed in parallel next for each worker call dan function and pass in the worker that needs to run sequentially finally make a call to enqueue to schedule your tasks note if any worker creates and returns an output the work manager will pass the output as the input of the next worker in the chain workmanger is the recommended solution for all tasks that need to run longer than the user remains on a single screen whether the user navigates away from that screen the application or even the device restarts work manager guarantees that your tasks will be executed that's not all with work manager you can do a lot more such as observing the work request status and have back-off policies for retiring work you can also define periodic work requests which can run a particular worker repeatedly you can use text to take a particular work request text can be used to observe the work request status or cancel the request if it is no longer needed to learn more about features tips and techniques to use work major please check out the codelab articles and documentation linked below
Info
Channel: Android Developers
Views: 335
Rating: 5 out of 5
Keywords: purpose: Educate, pr_pr: Android, series: Android Basics in Kotlin, type: DevByte (deck cleanup 0-10min), workmanger, what is workmanager, how to use workmanager, android basics, android kotlin, android basics in kotlin, kotlin, developer, developers, android developer, android developers, google developers, android, google
Id: UOoDt1El1f4
Channel Id: undefined
Length: 4min 9sec (249 seconds)
Published: Tue Oct 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.