Select correct demonstration of WorkRequest cancellation.

Select correct demonstration of WorkRequest cancellation.
A . workManager.enqueue(OneTimeWorkRequest.Builder(FooWorker::class.java).build())
B . val request: WorkRequest = OneTimeWorkRequest.Builder (FooWorker::class.java).build() workManager.enqueue(request)
val status = workManager.getWorkInfoByIdLiveData(request.id) status.observe(…)
C . val request: WorkRequest = OneTimeWorkRequest.Builder (FooWorker::class.java).build() workManager.enqueue(request) workManager.cancelWorkById(request.id)
D . val request1: WorkRequest = OneTimeWorkRequest.Builder (FooWorker::class.java).build()
val request2: WorkRequest = OneTimeWorkRequest.Builder (BarWorker::class.java).build()
val request3: WorkRequest = OneTimeWorkRequest.Builder (BazWorker::class.java).build()
workManager.beginWith(request1, request2).then(request3).enqueue()
E . val request: WorkRequest = OneTimeWorkRequest.Builder (FooWorker::class.java).build()
workManager.enqueue(request) workManager.cancelWork(request)

Answer: C

Explanation:

Videos:

Working with WorkManager, from the 2018 Android Dev Summit WorkManager: Beyond the basics, from the 2019 Android Dev Summit

Reference: https://developer.android.com/reference/androidx/work/WorkManager?hl=en

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments