# WorkContinuation

Artifact: [androidx.work:work-runtime](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/WorkContinuation.java+class:androidx.work.WorkContinuation) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

*** ** * ** ***

<br />

```
public abstract class WorkContinuation
```

<br />

*** ** * ** ***

A class that allows you to chain together `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s. WorkContinuations allow the user to create arbitrary acyclic graphs of work dependencies. You can add dependent work to a WorkContinuation by invoking `https://developer.android.com/reference/androidx/work/WorkContinuation#then(androidx.work.OneTimeWorkRequest)` or its variants. This returns a new WorkContinuation.

To construct more complex graphs, `https://developer.android.com/reference/androidx/work/WorkContinuation#combine(java.util.List<androidx.work.WorkContinuation>)` 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 `https://developer.android.com/reference/androidx/work/WorkContinuation#enqueue()` to inform WorkManager to actually enqueue the work graph. As usual, enqueues are asynchronous - you can observe or block on the returned `https://developer.android.com/reference/androidx/work/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 |
|---|
| `https://developer.android.com/reference/androidx/work/WorkContinuation#WorkContinuation()()` |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkContinuation` | `https://developer.android.com/reference/androidx/work/WorkContinuation#combine(java.util.List<androidx.work.WorkContinuation>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/WorkContinuation> continuations)` Combines multiple `https://developer.android.com/reference/androidx/work/WorkContinuation`s as prerequisites for a new WorkContinuation to allow for complex chaining. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/Operation` | `https://developer.android.com/reference/androidx/work/WorkContinuation#enqueue()()` Enqueues the instance of `https://developer.android.com/reference/androidx/work/WorkContinuation` on the background thread. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/androidx/work/WorkContinuation#getWorkInfos()()` Returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of a `https://developer.android.com/reference/java/util/List.html` of `https://developer.android.com/reference/androidx/work/WorkInfo`s that provides information about the status of each `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` in this `https://developer.android.com/reference/androidx/work/WorkContinuation`, as well as their prerequisites. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LiveData<https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/androidx/work/WorkContinuation#getWorkInfosLiveData()()` Returns a `https://developer.android.com/reference/androidx/lifecycle/LiveData` list of `https://developer.android.com/reference/androidx/work/WorkInfo`s that provide information about the status of each `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` in this `https://developer.android.com/reference/androidx/work/WorkContinuation`, as well as their prerequisites. |
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkContinuation` | `https://developer.android.com/reference/androidx/work/WorkContinuation#then(java.util.List<androidx.work.OneTimeWorkRequest>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/OneTimeWorkRequest> work)` Adds new `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` items that depend on the successful completion of all previously added `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkContinuation` | `https://developer.android.com/reference/androidx/work/WorkContinuation#then(androidx.work.OneTimeWorkRequest)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/OneTimeWorkRequest work)` Adds new `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` items that depend on the successful completion of all previously added `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s. |

## Public constructors

### WorkContinuation

Added in 1.0.0

```
public WorkContinuation()
```

## Public methods

### combine

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

```
public static @NonNull WorkContinuation combine(@NonNull List<WorkContinuation> continuations)
```

Combines multiple `https://developer.android.com/reference/androidx/work/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
    |       |
    +---+
        |
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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/WorkContinuation> continuations` | One or more `https://developer.android.com/reference/androidx/work/WorkContinuation`s that are prerequisites for the return value |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/androidx/work/WorkContinuation` that allows further chaining |

### enqueue

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

```
public abstract @NonNull Operation enqueue()
```

Enqueues the instance of `https://developer.android.com/reference/androidx/work/WorkContinuation` on the background thread.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/Operation` | An `https://developer.android.com/reference/androidx/work/Operation` that can be used to determine when the enqueue has completed |

### getWorkInfos

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

```
public abstract @NonNull ListenableFuture<List<WorkInfo>> getWorkInfos()
```

Returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of a `https://developer.android.com/reference/java/util/List.html` of `https://developer.android.com/reference/androidx/work/WorkInfo`s that provides information about the status of each `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` in this `https://developer.android.com/reference/androidx/work/WorkContinuation`, as well as their prerequisites.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/WorkInfo>>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of a `https://developer.android.com/reference/java/util/List.html` of `https://developer.android.com/reference/androidx/work/WorkInfo`s |

### getWorkInfosLiveData

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

```
public abstract @NonNull LiveData<List<WorkInfo>> getWorkInfosLiveData()
```

Returns a `https://developer.android.com/reference/androidx/lifecycle/LiveData` list of `https://developer.android.com/reference/androidx/work/WorkInfo`s that provide information about the status of each `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` in this `https://developer.android.com/reference/androidx/work/WorkContinuation`, as well as their prerequisites. If the state or outputs of any of the work changes, any attached `https://developer.android.com/reference/androidx/lifecycle/Observer`s will trigger.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/LiveData<https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/WorkInfo>>` | A `https://developer.android.com/reference/androidx/lifecycle/LiveData` containing a list of `https://developer.android.com/reference/androidx/work/WorkInfo`s; you must use `https://developer.android.com/reference/androidx/lifecycle/LiveData#observe(androidx.lifecycle.LifecycleOwner,androidx.lifecycle.Observer<? super T>)` to receive updates |

### then

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

```
public abstract @NonNull WorkContinuation then(@NonNull List<OneTimeWorkRequest> work)
```

Adds new `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` items that depend on the successful completion of all previously added `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/work/OneTimeWorkRequest> work` | One or more `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` to add as dependents |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/androidx/work/WorkContinuation` that allows for further chaining of dependent `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s |

### then

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/work#1.0.0)

```
public final @NonNull WorkContinuation then(@NonNull OneTimeWorkRequest work)
```

Adds new `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest` items that depend on the successful completion of all previously added `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/OneTimeWorkRequest work` | One or more `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s to add as dependents |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/androidx/work/WorkContinuation` that allows for further chaining of dependent `https://developer.android.com/reference/androidx/work/OneTimeWorkRequest`s |