WorkContinuation
public
abstract
class
WorkContinuation
extends Object
| java.lang.Object | |
| ↳ | androidx.work.WorkContinuation |
A class that allows you to chain together OneTimeWorkRequests. 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, 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
| |
+-------+
|
E
you would write the following:
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();
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 | |
|---|---|
WorkContinuation()
|
|
Public methods | |
|---|---|
static
WorkContinuation
|
combine(List<WorkContinuation> continuations)
Combines multiple |
abstract
Operation
|
enqueue()
Enqueues the instance of |
abstract
ListenableFuture<List<WorkInfo>>
|
getWorkInfos()
Returns a |
abstract
LiveData<List<WorkInfo>>
|
getWorkInfosLiveData()
Returns a |
final
WorkContinuation
|
then(OneTimeWorkRequest work)
Adds new |
abstract
WorkContinuation
|
then(List<OneTimeWorkRequest> work)
Adds new |
Inherited methods | |
|---|---|
Public constructors
WorkContinuation
public WorkContinuation ()
Public methods
combine
public static WorkContinuation combine (List<WorkContinuation> continuations)
Combines multiple WorkContinuations as prerequisites for a new WorkContinuation to
allow for complex chaining. For example, to create a graph like this:
A C
| |
B D
| |
+-------+
|
E
you would write the following:
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();
| Parameters | |
|---|---|
continuations |
List: One or more WorkContinuations that are prerequisites for the
return value |
| Returns | |
|---|---|
WorkContinuation |
A WorkContinuation that allows further chaining
|
enqueue
public abstract Operation enqueue ()
Enqueues the instance of WorkContinuation on the background thread.
| Returns | |
|---|---|
Operation |
An Operation that can be used to determine when the enqueue has completed
|
getWorkInfos
public abstract ListenableFuture<List<WorkInfo>> getWorkInfos ()
Returns a ListenableFuture of a List of WorkInfos that provides
information about the status of each OneTimeWorkRequest in this
WorkContinuation, as well as their prerequisites.
| Returns | |
|---|---|
ListenableFuture<List<WorkInfo>> |
A ListenableFuture of a List of WorkInfos
|
getWorkInfosLiveData
public abstract LiveData<List<WorkInfo>> getWorkInfosLiveData ()
Returns a LiveData list of WorkInfos 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
Observers will trigger.
| Returns | |
|---|---|
LiveData<List<WorkInfo>> |
A LiveData containing a list of WorkInfos; you must use
LiveData.observe(LifecycleOwner, Observer) to receive updates
|
then
public final WorkContinuation then (OneTimeWorkRequest work)
Adds new OneTimeWorkRequest items that depend on the successful completion of
all previously added OneTimeWorkRequests.
| Parameters | |
|---|---|
work |
OneTimeWorkRequest: One or more OneTimeWorkRequests to add as dependents |
| Returns | |
|---|---|
WorkContinuation |
A WorkContinuation that allows for further chaining of dependent
OneTimeWorkRequests
|
then
public abstract WorkContinuation then (List<OneTimeWorkRequest> work)
Adds new OneTimeWorkRequest items that depend on the successful completion
of all previously added OneTimeWorkRequests.
| Parameters | |
|---|---|
work |
List: One or more OneTimeWorkRequest to add as dependents |
| Returns | |
|---|---|
WorkContinuation |
A WorkContinuation that allows for further chaining of dependent
OneTimeWorkRequests
|