WorkContinuation
abstract class WorkContinuation
kotlin.Any | |
↳ | androidx.work.WorkContinuation |
A class that allows you to chain together OneTimeWorkRequest
s. WorkContinuations allow the user to create arbitrary acyclic graphs of work dependencies. You can add dependent work to a WorkContinuation by invoking then(OneTimeWorkRequest)
or its variants. This returns a new WorkContinuation.
To construct more complex graphs, WorkContinuation#combine(List)
or its variants can be used to return a WorkContinuation with the input WorkContinuations as prerequisites. To create a graph like this:
A C | | B D | | +-------+ | Eyou would write the following:
<code>WorkContinuation left = workManager.beginWith(A).then(B); WorkContinuation right = workManager.beginWith(C).then(D); WorkContinuation final = WorkContinuation.combine(Arrays.asList(left, right)).then(E); final.enqueue();</code>Not that enqueuing a WorkContinuation enqueues all previously-unenqueued prerequisites. You must call
enqueue()
to inform WorkManager to actually enqueue the work graph. As usual, enqueues are asynchronous - you can observe or block on the returned Operation
if you need to be informed about its completion.
Because of the fluent nature of this class, its existence should be invisible in most cases.
Summary
Public constructors | |
---|---|
<init>() A class that allows you to chain together |
Public methods | |
---|---|
open static WorkContinuation |
combine(@NonNull continuations: MutableList<WorkContinuation!>) Combines multiple |
abstract Operation |
enqueue() Enqueues the instance of |
abstract ListenableFuture<MutableList<WorkInfo!>!> |
Returns a |
abstract LiveData<MutableList<WorkInfo!>!> |
Returns a |
WorkContinuation |
then(@NonNull work: OneTimeWorkRequest) Adds new |
abstract WorkContinuation |
then(@NonNull work: MutableList<OneTimeWorkRequest!>) Adds new |
Public constructors
<init>
WorkContinuation()
A class that allows you to chain together OneTimeWorkRequest
s. WorkContinuations allow the user to create arbitrary acyclic graphs of work dependencies. You can add dependent work to a WorkContinuation by invoking then(OneTimeWorkRequest)
or its variants. This returns a new WorkContinuation.
To construct more complex graphs, WorkContinuation#combine(List)
or its variants can be used to return a WorkContinuation with the input WorkContinuations as prerequisites. To create a graph like this:
A C | | B D | | +-------+ | Eyou would write the following:
<code>WorkContinuation left = workManager.beginWith(A).then(B); WorkContinuation right = workManager.beginWith(C).then(D); WorkContinuation final = WorkContinuation.combine(Arrays.asList(left, right)).then(E); final.enqueue();</code>Not that enqueuing a WorkContinuation enqueues all previously-unenqueued prerequisites. You must call
enqueue()
to inform WorkManager to actually enqueue the work graph. As usual, enqueues are asynchronous - you can observe or block on the returned Operation
if you need to be informed about its completion.
Because of the fluent nature of this class, its existence should be invisible in most cases.
Public methods
combine
@NonNull open static fun combine(@NonNull continuations: MutableList<WorkContinuation!>): WorkContinuation
Combines multiple WorkContinuation
s as prerequisites for a new WorkContinuation to allow for complex chaining. For example, to create a graph like this:
A C | | B D | | +-------+ | Eyou would write the following:
<code>WorkContinuation left = workManager.beginWith(A).then(B); WorkContinuation right = workManager.beginWith(C).then(D); WorkContinuation final = WorkContinuation.combine(Arrays.asList(left, right)).then(E); final.enqueue();</code>
Parameters | |
---|---|
continuations |
MutableList<WorkContinuation!>: One or more WorkContinuation s that are prerequisites for the return value |
Return | |
---|---|
WorkContinuation |
A WorkContinuation that allows further chaining |
enqueue
@NonNull abstract fun enqueue(): Operation
Enqueues the instance of WorkContinuation
on the background thread.
Return | |
---|---|
Operation |
An Operation that can be used to determine when the enqueue has completed |
getWorkInfos
@NonNull abstract fun getWorkInfos(): ListenableFuture<MutableList<WorkInfo!>!>
Returns a ListenableFuture
of a List
of WorkInfo
s that provides information about the status of each OneTimeWorkRequest
in this WorkContinuation
, as well as their prerequisites.
Return | |
---|---|
ListenableFuture<MutableList<WorkInfo!>!> |
A ListenableFuture of a List of WorkInfo s |
getWorkInfosLiveData
@NonNull abstract fun getWorkInfosLiveData(): LiveData<MutableList<WorkInfo!>!>
Returns a LiveData
list of WorkInfo
s that provide information about the status of each OneTimeWorkRequest
in this WorkContinuation
, as well as their prerequisites. If the state or outputs of any of the work changes, any attached Observer
s will trigger.
Return | |
---|---|
LiveData<MutableList<WorkInfo!>!> |
A LiveData containing a list of WorkInfo s; you must use LiveData#observe(LifecycleOwner, Observer) to receive updates |
then
@NonNull fun then(@NonNull work: OneTimeWorkRequest): WorkContinuation
Adds new OneTimeWorkRequest
items that depend on the successf