WorkManager is an API that makes it easy to schedule asynchronous tasks that need to run when various constraints are met. It supports one-off and periodic tasks, chained tasks with inputs and outputs, and allows constraints to be set on when tasks run. The latest version of WorkManager provides a better in-process scheduler, new diagnostic APIs, and lint checks. It also supports RxJava 3.
Pollinator Ambassador Earth Steward Day Presentation 2024-05-22
What's new in WorkManager-Andri Suranta Ginting (Product Engineer-Gojek)
1. What’s new in WorkManager
Andri Suranta Ginting - Product Engineer at Gojek
2. Plan
● What is WorkManager
● Why WorkManager
● Benefits Using WorkManager
● WorkManager Type
● Latest Update From WorkManager 2.4
3. WorkManager
WorkManager is an API that makes it easy to
● Schedule Deferrable
● Asynchronous tasks
WorkManager handles background work that needs to run when various
constraints are met
6. Benefits
● Support asynchronous one-off and
periodic tasks
● Support chained tasks with input/output
Filter Images 1 Filter Images 2
Compress
Upload
7. Benefits
● Support asynchronous one-off and
periodic tasks
● Support chained tasks with input/output
● Let you set constraints on when the task
runs
Filter Images 1 Filter Images 2
Compress
Upload
Battery
Not
low
Has
Network
8. Benefits
● Support asynchronous one-off and
periodic tasks
● Support chained tasks with input/output
● Let you set constraints on when the task
runs
● Guarantees task execution, even if the
apps is restart
● Handle compatibility with different OS
version
● Follow System health best practice
Filter Images 1 Filter Images 2
Compress
Upload
Battery
Not
low
Has
Network
21. Unique Worker
There are 3 policies for unique worker that applied for OneTimeWorker
● KEEP
● REPLACE
● APPEND
There are 2 policies for unique worker that applied for PeriodicWorker
● KEEP
● REPLACE
24. Better Diagnostics
Introduce new API that can invoke with ADB
//pass logcat to adb
adb shell am broadcast
-a "androidx.work.diagnostic.REQUEST_DIAGNOSTIC"
-p "package_name"
//view logcat
adb logcat
25. Better Diagnostics
Introduce new API that can invoke with ADB
//pass logcat to adb
adb shell am broadcast
-a "androidx.work.diagnostic.REQUEST_DIAGNOSTIC"
-p "package_name"
//view logcat
adb logcat
26. Lint Checks
class ImageFilterWork(
context: Context,
params: WorkerParameters
): CoroutineWorker(context, params) {
override suspend fun doWork(): Result {
return Result.success()
}
}
27. Lint Checks
private class ImageFilterWork(
context: Context,
params: WorkerParameters
): CoroutineWorker(context, params) {
override suspend fun doWork(): Result {
return Result.success()
}
}
Error: ImageFilterWorker
need to public