Using WorkManager to manage background tasks - free course from AndroidSchool.ru, training 2 hours, Date November 28, 2023.
Miscellaneous / / November 30, 2023
At every stage of development of the Android operating system, there were different ways to work with background tasks, including when the application is “killed” by the operating system - but some kind of task must be running in the background logics. For example JobScheduler, GCM Network Manager, FirebaseJobDispatcher or Android Job by Evernote. And at Google I/O 2018, Google announced the WorkManager library, which is the recommended way to manage tasks that must be performed on a non-UI thread, even when the user is no longer actively interacting with application.
Tasks effectively solved using WorkManager:
- Execute network requests at specified intervals
- Clearing the database cache once a day
- Updating information for widgets
- Sequential execution of background tasks
- Downloading heavy files
- User geolocation tracking
As you can see, the areas of application of WorkManager are very diverse and that is why we will look at practical examples of how to manage such tasks through WorkManager. In this course you will learn how to work with the WorkManager library, learn how to launch different types of workers to perform background tasks.
You will master:
- Running background tasks without running the application via WorkManager
- Conditions for starting a background task using Constraints (network presence, battery status, etc.)
- Types of tasks OneTimeWorkRequest and PeriodicWorkRequest
- Working with RxWorker
- Methods for obtaining geolocation through FusedLocationProviderClient
- Room for storing information as a local database
- Flipper as a tool for debugging Android applications
The source code, lessons and course materials are available free of charge to registered users.
WorkManager for managing background tasks
Lecture1.1
Categories of background tasks 15 min. Preview
Lecture1.2
Why do you need WorkManager? 05 min. Preview
Lecture1.3
What tasks is WorkManager suitable for? 05 min. Preview
Lecture1.4
Project description – Geotracker 05 min.
Lecture1.5
Anatomy of WorkManager. Basic classes 05 min. Preview
Lecture1.6
Creating a project and adding the necessary dependencies 10 min.
Lecture1.7
Creating a simple database based on Room to store coordinates 15 min.
Lecture1.8
Viewing information in a database using Flipper 10 min.
Lecture1.9
Example of one-time execution of WorkManager using OneTimeWorkRequest 20 min.
Lecture1.10
Criteria for completing the task: availability of Wi-Fi, sufficient battery charge and other 15 minutes.
Lecture1.11
Conflict resolution policies for background tasks and recurrence modes 10 min.
Lecture1.12
Getting coordinates via FusedLocationProviderClient 15 min.
Lecture1.13
Save the coordinates to the Room database 10 min.
Lecture1.14
We launch the geotracker once every 15 minutes using PeriodicWorkRequest 05 min.
Lecture1.15
Useful links and materials 01 min.