# WorkManager

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

*** ** * ** ***


```
abstract class WorkManager
```

<br />

*** ** * ** ***

WorkManager is the recommended library for persistent work. Scheduled work is guaranteed to execute sometime after its `https://developer.android.com/reference/kotlin/androidx/work/Constraints` are met. WorkManager allows observation of work status and the ability to create complex chains of work.

WorkManager uses an underlying job dispatching service when available based on the following criteria:

- Uses JobScheduler for API 23+

- Uses a custom AlarmManager + BroadcastReceiver implementation for API 14-22

All work must be done in a `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker` class. A simple implementation, `https://developer.android.com/reference/kotlin/androidx/work/Worker`, is recommended as the starting point for most developers. With the optional dependencies, you can also use `CoroutineWorker` or `RxWorker`. All background work is given a maximum of ten minutes to finish its execution. After this time has expired, the worker will be signalled to stop.

There are two types of work supported by WorkManager: `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` and `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest`. You can enqueue requests using WorkManager as follows:

```kotlin
WorkManager workManager = WorkManager.getInstance(Context);
workManager.enqueue(new OneTimeWorkRequest.Builder(FooWorker.class).build());
```

A `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` has an associated id that can be used for lookups and observation as follows:

```kotlin
WorkRequest request = new OneTimeWorkRequest.Builder(FooWorker.class).build();
workManager.enqueue(request);
LiveData<WorkInfo> status = workManager.getWorkInfoByIdLiveData(request.getId());
status.observe(...);
```

You can also use the id for cancellation:

```kotlin
WorkRequest request = new OneTimeWorkRequest.Builder(FooWorker.class).build();
workManager.enqueue(request);
workManager.cancelWorkById(request.getId());
```

You can chain work as follows:

```kotlin
WorkRequest request1 = new OneTimeWorkRequest.Builder(FooWorker.class).build();
WorkRequest request2 = new OneTimeWorkRequest.Builder(BarWorker.class).build();
WorkRequest request3 = new OneTimeWorkRequest.Builder(BazWorker.class).build();
workManager.beginWith(request1, request2).then(request3).enqueue();
```

Each call to `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#beginWith(androidx.work.OneTimeWorkRequest)` returns a `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` upon which you can call `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation#then(androidx.work.OneTimeWorkRequest)` with a single `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` or a list of `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` to chain further work. This allows for creation of complex chains of work. For example, to create a chain like this:

```kotlin
         A
         |
   +---+
   |          |
   B          C
   |
+---+
|    |
D    E
```

you would enqueue them as follows:

```kotlin
WorkContinuation continuation = workManager.beginWith(A);
continuation.then(B).then(D, E).enqueue();  // A is implicitly enqueued here
continuation.then(C).enqueue();
```

Work is eligible for execution when all of its prerequisites are complete. If any of its prerequisites fail or are cancelled, the work will never run.

WorkRequests can accept `https://developer.android.com/reference/kotlin/androidx/work/Constraints`, inputs (see `https://developer.android.com/reference/kotlin/androidx/work/Data`), and backoff criteria. WorkRequests can be tagged with human-readable Strings (see `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest.Builder#addTag(kotlin.String)`), and chains of work can be given a uniquely-identifiable name (see `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#beginUniqueWork(kotlin.String,androidx.work.ExistingWorkPolicy,androidx.work.OneTimeWorkRequest)`).

### Initializing WorkManager

By default, WorkManager auto-initializes itself using a built-in `ContentProvider`. ContentProviders are created and run before the `Application` object, so this allows the WorkManager singleton to be setup before your code can run in most cases. This is suitable for most developers. However, you can provide a custom `https://developer.android.com/reference/kotlin/androidx/work/Configuration` by using `https://developer.android.com/reference/kotlin/androidx/work/Configuration.Provider` or `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#initialize(android.content.Context,androidx.work.Configuration)`.

### Renaming and Removing ListenableWorker Classes

Exercise caution in renaming classes derived from `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker`s. WorkManager stores the class name in its internal database when the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is enqueued so it can later create an instance of that worker when constraints are met. Unless otherwise specified in the WorkManager `https://developer.android.com/reference/kotlin/androidx/work/Configuration`, this is done in the default `https://developer.android.com/reference/kotlin/androidx/work/WorkerFactory` which tries to reflectively create the ListenableWorker object. Therefore, renaming or removing these classes is dangerous - if there is pending work with the given class, it will fail permanently if the class cannot be found. If you are using a custom WorkerFactory, make sure you properly handle cases where the class is not found so that your code does not crash.

In case it is desirable to rename a class, implement a custom WorkerFactory that instantiates the right ListenableWorker for the old class name.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult>` An enumeration of results for `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#updateWork(androidx.work.WorkRequest)` method. |

| ### Public companion functions |
|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/work/WorkManager` | `[getInstance](https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getInstance())()` **This function is deprecated.** Use the overload receiving Context |
| `open https://developer.android.com/reference/kotlin/androidx/work/WorkManager` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getInstance(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html)` Retrieves the `default` singleton instance of `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#initialize(android.content.Context,androidx.work.Configuration)(context: https://developer.android.com/reference/android/content/Context.html, configuration: https://developer.android.com/reference/kotlin/androidx/work/Configuration)` Used to do a one-time initialization of the `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` singleton with a custom `https://developer.android.com/reference/kotlin/androidx/work/Configuration`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#isInitialized()()` Provides a way to check if `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` is initialized in this process. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#beginUniqueWork(kotlin.String,androidx.work.ExistingWorkPolicy,androidx.work.OneTimeWorkRequest)( uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy, request: https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest )` This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#beginUniqueWork(kotlin.String,androidx.work.ExistingWorkPolicy,kotlin.collections.List)( uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy, requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest> )` This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. |
| `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#beginWith(androidx.work.OneTimeWorkRequest)(request: https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest)` Begins a chain with one or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest`s, which can be enqueued together in the future using `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation#enqueue()`. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#beginWith(kotlin.collections.List)(requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest>)` Begins a chain with one or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest`s, which can be enqueued together in the future using `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation#enqueue()`. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#cancelAllWork()()` Cancels all unfinished work. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#cancelAllWorkByTag(kotlin.String)(tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Cancels all unfinished work with the given tag. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#cancelUniqueWork(kotlin.String)(uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Cancels all unfinished work in the work chain with the given name. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#cancelWorkById(java.util.UUID)(id: https://developer.android.com/reference/java/util/UUID.html)` Cancels work with the given id if it isn't finished. |
| `abstract https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#createCancelPendingIntent(java.util.UUID)(id: https://developer.android.com/reference/java/util/UUID.html)` Creates a `https://developer.android.com/reference/android/app/PendingIntent.html` which can be used to cancel a `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` with the given `id`. |
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#enqueue(androidx.work.WorkRequest)(request: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)` Enqueues one item for background processing. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#enqueue(kotlin.collections.List)(requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkRequest>)` Enqueues one or more items for background processing. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#enqueueUniquePeriodicWork(kotlin.String,androidx.work.ExistingPeriodicWorkPolicy,androidx.work.PeriodicWorkRequest)( uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, existingPeriodicWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingPeriodicWorkPolicy, request: https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest )` This method allows you to enqueue a uniquely-named `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest`, where only one PeriodicWorkRequest of a particular name can be active at a time. |
| `open https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#enqueueUniqueWork(kotlin.String,androidx.work.ExistingWorkPolicy,androidx.work.OneTimeWorkRequest)( uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy, request: https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest )` This method allows you to enqueue `work` requests to a uniquely-named `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation`, where only one continuation of a particular name can be active at a time. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#enqueueUniqueWork(kotlin.String,androidx.work.ExistingWorkPolicy,kotlin.collections.List)( uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy, requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest> )` This method allows you to enqueue `work` requests to a uniquely-named `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation`, where only one continuation of a particular name can be active at a time. |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getLastCancelAllTimeMillis()()` Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the last time all work was cancelled. |
| `abstract https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getLastCancelAllTimeMillisLiveData()()` Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the last time all work was cancelled. |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo?>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfoById(java.util.UUID)(id: https://developer.android.com/reference/java/util/UUID.html)` Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for a given work id. |
| `abstract https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo?>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfoByIdFlow(java.util.UUID)(id: https://developer.android.com/reference/java/util/UUID.html)` Gets a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for a given work id. |
| `abstract https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo?>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfoByIdLiveData(java.util.UUID)(id: https://developer.android.com/reference/java/util/UUID.html)` Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for a given work id. |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfos(androidx.work.WorkQuery)(workQuery: https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)` Gets the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work referenced by the `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` specification. |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosByTag(kotlin.String)(tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work for a given tag. |
| `abstract https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosByTagFlow(kotlin.String)(tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work for a given tag. |
| `abstract https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosByTagLiveData(kotlin.String)(tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work for a given tag. |
| `abstract https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosFlow(androidx.work.WorkQuery)(workQuery: https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)` Gets the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work referenced by the `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` specification. |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosForUniqueWork(kotlin.String)(uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work in a work chain with a given unique name. |
| `abstract https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosForUniqueWorkFlow(kotlin.String)(uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work in a work chain with a given unique name. |
| `abstract https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosForUniqueWorkLiveData(kotlin.String)(uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work in a work chain with a given unique name. |
| `abstract https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getWorkInfosLiveData(androidx.work.WorkQuery)(workQuery: https://developer.android.com/reference/kotlin/androidx/work/WorkQuery)` Gets the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work referenced by the `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` specification. |
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Operation` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#pruneWork()()` Prunes all eligible finished work from the internal database. |
| `abstract https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult>` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#updateWork(androidx.work.WorkRequest)(request: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest)` Updates the work with the new specification. |

| ### Public properties |
|---|---|
| `abstract https://developer.android.com/reference/kotlin/androidx/work/Configuration` | `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#configuration()` The `https://developer.android.com/reference/kotlin/androidx/work/Configuration` instance that `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` was initialized with. |

## Public companion functions

### getInstance

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

```
open fun [getInstance](https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getInstance())(): WorkManager
```

> [!CAUTION]
> **This function is deprecated.**   
> Use the overload receiving Context, use this instead:
>
> ```kotlin
> WorkManager.getContext(context)
> ```

Retrieves the `default` singleton instance of `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` | The singleton instance of `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`; this may be `null` in unusual circumstances where you have disabled automatic initialization and have failed to manually call `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#initialize(android.content.Context,androidx.work.Configuration)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If WorkManager is not initialized properly as per the exception message. |

### getInstance

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

```
open fun getInstance(context: Context): WorkManager
```

Retrieves the `default` singleton instance of `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | A `https://developer.android.com/reference/android/content/Context.html` for on-demand initialization. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` | The singleton instance of `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`; this may be `null` in unusual circumstances where you have disabled automatic initialization and have failed to manually call `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#initialize(android.content.Context,androidx.work.Configuration)`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If WorkManager is not initialized properly |

### initialize

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

```
open fun initialize(context: Context, configuration: Configuration): Unit
```

Used to do a one-time initialization of the `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` singleton with a custom `https://developer.android.com/reference/kotlin/androidx/work/Configuration`. By default, this method should not be called because WorkManager is automatically initialized. To initialize WorkManager yourself, please follow these steps:

- Disable `androidx.work.WorkManagerInitializer` in your manifest.

- Invoke this method in `Application#onCreate` or a `ContentProvider`. Note that this method **must** be invoked in one of these two places or you risk getting a `NullPointerException` in `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#getInstance()`.

This method throws an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` when attempting to initialize in direct boot mode.

This method throws an exception if it is called multiple times.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | A `https://developer.android.com/reference/android/content/Context.html` object for configuration purposes. Internally, this class will call `https://developer.android.com/reference/android/content/Context.html#getApplicationContext()`, so you may safely pass in any Context without risking a memory leak. |
| `configuration: https://developer.android.com/reference/kotlin/androidx/work/Configuration` | The `https://developer.android.com/reference/kotlin/androidx/work/Configuration` for used to set up WorkManager. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Configuration.Provider` | for on-demand initialization. |

### isInitialized

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

```
open fun isInitialized(): Boolean
```

Provides a way to check if `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` is initialized in this process.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` has been initialized in this process. |

## Public functions

### beginUniqueWork

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

```
fun beginUniqueWork(
    uniqueWorkName: String,
    existingWorkPolicy: ExistingWorkPolicy,
    request: OneTimeWorkRequest
): WorkContinuation
```

This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.

The `uniqueWorkName` uniquely identifies this set of work.

If this method determines that new work should be enqueued and run, all records of previous work with `uniqueWorkName` will be pruned. If this method determines that new work should NOT be run, then the entire chain will be considered a no-op.

If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run. This is particularly important if you are using `APPEND` as your `https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy`.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A unique name which for this chain of work |
| `existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy` | An `https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy` |
| `request: https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` | The `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` to enqueue. `REPLACE` ensures that if there is pending work labelled with `uniqueWorkName`, it will be cancelled and the new work will run. `KEEP` will run the new sequence of work only if there is no pending work labelled with `uniqueWorkName`. `APPEND` will create a new sequence of work if there is no existing work with `uniqueWorkName`; otherwise, `work` will be added as a child of all leaf nodes labelled with `uniqueWorkName`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` that allows further chaining |

### beginUniqueWork

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

```
abstract fun beginUniqueWork(
    uniqueWorkName: String,
    existingWorkPolicy: ExistingWorkPolicy,
    requests: List<OneTimeWorkRequest>
): WorkContinuation
```

This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.

The `uniqueWorkName` uniquely identifies this set of work.

If this method determines that new work should be enqueued and run, all records of previous work with `uniqueWorkName` will be pruned. If this method determines that new work should NOT be run, then the entire chain will be considered a no-op.

If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run. This is particularly important if you are using `APPEND` as your `https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy`.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A unique name which for this chain of work |
| `existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy` | An `https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy`; see below for more information |
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest>` | One or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` to enqueue. `REPLACE` ensures that if there is pending work labelled with `uniqueWorkName`, it will be cancelled and the new work will run. `KEEP` will run the new sequence of work only if there is no pending work labelled with `uniqueWorkName`. `APPEND` will create a new sequence of work if there is no existing work with `uniqueWorkName`; otherwise, `work` will be added as a child of all leaf nodes labelled with `uniqueWorkName`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` that allows further chaining |

### beginWith

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

```
fun beginWith(request: OneTimeWorkRequest): WorkContinuation
```

Begins a chain with one or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest`s, which can be enqueued together in the future using `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation#enqueue()`.

If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` | One or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` to start a chain of work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` that allows for further chaining of dependent `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` |

### beginWith

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

```
abstract fun beginWith(requests: List<OneTimeWorkRequest>): WorkContinuation
```

Begins a chain with one or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest`s, which can be enqueued together in the future using `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation#enqueue()`.

If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run.

| Parameters |
|---|---|
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest>` | One or more `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` to start a chain of work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` | A `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation` that allows for further chaining of dependent `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` |

### cancelAllWork

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

```
abstract fun cancelAllWork(): Operation
```

Cancels all unfinished work. **Use this method with extreme caution!** By invoking it, you will potentially affect other modules or libraries in your codebase. It is strongly recommended that you use one of the other cancellation methods at your disposal.

Upon cancellation, `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` returned by `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#startWork()` will be cancelled. Also `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#onStopped()` will be invoked for any affected workers.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the cancelAllWork has completed |

### cancelAllWorkByTag

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

```
abstract fun cancelAllWorkByTag(tag: String): Operation
```

Cancels all unfinished work with the given tag. Note that cancellation is a best-effort policy and work that is already executing may continue to run. Upon cancellation, `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` returned by `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#startWork()` will be cancelled. Also `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#onStopped()` will be invoked for any affected workers.

| Parameters |
|---|---|
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tag used to identify the work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the cancelAllWorkByTag has completed |

### cancelUniqueWork

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

```
abstract fun cancelUniqueWork(uniqueWorkName: String): Operation
```

Cancels all unfinished work in the work chain with the given name. Note that cancellation is a best-effort policy and work that is already executing may continue to run. Upon cancellation, `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` returned by `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#startWork()` will be cancelled. Also `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#onStopped()` will be invoked for any affected workers.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The unique name used to identify the chain of work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the cancelUniqueWork has completed |

### cancelWorkById

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

```
abstract fun cancelWorkById(id: UUID): Operation
```

Cancels work with the given id if it isn't finished. Note that cancellation is a best-effort policy and work that is already executing may continue to run. Upon cancellation, `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` returned by `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#startWork()` will be cancelled. Also `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#onStopped()` will be invoked for any affected workers.

| Parameters |
|---|---|
| `id: https://developer.android.com/reference/java/util/UUID.html` | The id of the work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the cancelWorkById has completed |

### createCancelPendingIntent

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

```
abstract fun createCancelPendingIntent(id: UUID): PendingIntent
```

Creates a `https://developer.android.com/reference/android/app/PendingIntent.html` which can be used to cancel a `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` with the given `id`.

| Parameters |
|---|---|
| `id: https://developer.android.com/reference/java/util/UUID.html` | The `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` id. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent.html` | The `https://developer.android.com/reference/android/app/PendingIntent.html` that can be used to cancel the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`. |

### enqueue

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

```
fun enqueue(request: WorkRequest): Operation
```

Enqueues one item for background processing.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` | The `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to enqueue |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the enqueue has completed |

### enqueue

```
abstract fun enqueue(requests: List<WorkRequest>): Operation
```

Enqueues one or more items for background processing.

| Parameters |
|---|---|
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkRequest>` | One or more `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` to enqueue |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the enqueue has completed |

### enqueueUniquePeriodicWork

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

```
abstract fun enqueueUniquePeriodicWork(
    uniqueWorkName: String,
    existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy,
    request: PeriodicWorkRequest
): Operation
```

This method allows you to enqueue a uniquely-named `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest`, where only one PeriodicWorkRequest of a particular name can be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.

The `uniqueWorkName` uniquely identifies this PeriodicWorkRequest.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A unique name which for this operation |
| `existingPeriodicWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingPeriodicWorkPolicy` | An `https://developer.android.com/reference/kotlin/androidx/work/ExistingPeriodicWorkPolicy` |
| `request: https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest` | A `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest` to enqueue. `REPLACE` ensures that if there is pending work labelled with `uniqueWorkName`, it will be cancelled and the new work will run. `KEEP` will run the new PeriodicWorkRequest only if there is no pending work labelled with `uniqueWorkName`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the enqueue has completed |

### enqueueUniqueWork

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

```
open fun enqueueUniqueWork(
    uniqueWorkName: String,
    existingWorkPolicy: ExistingWorkPolicy,
    request: OneTimeWorkRequest
): Operation
```

This method allows you to enqueue `work` requests to a uniquely-named `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation`, where only one continuation of a particular name can be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.

The `uniqueWorkName` uniquely identifies this `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation`.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A unique name which for this operation |
| `existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy` | An `https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy`; see below for more information |
| `request: https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` | The `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest`s to enqueue. `REPLACE` ensures that if there is pending work labelled with `uniqueWorkName`, it will be cancelled and the new work will run. `KEEP` will run the new OneTimeWorkRequests only if there is no pending work labelled with `uniqueWorkName`. `APPEND` will append the OneTimeWorkRequests as leaf nodes labelled with `uniqueWorkName`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the enqueue has completed |

### enqueueUniqueWork

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

```
abstract fun enqueueUniqueWork(
    uniqueWorkName: String,
    existingWorkPolicy: ExistingWorkPolicy,
    requests: List<OneTimeWorkRequest>
): Operation
```

This method allows you to enqueue `work` requests to a uniquely-named `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation`, where only one continuation of a particular name can be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.

The `uniqueWorkName` uniquely identifies this `https://developer.android.com/reference/kotlin/androidx/work/WorkContinuation`.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | A unique name which for this operation |
| `existingWorkPolicy: https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy` | An `https://developer.android.com/reference/kotlin/androidx/work/ExistingWorkPolicy` |
| `requests: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest>` | `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest`s to enqueue. `REPLACE` ensures that if there is pending work labelled with `uniqueWorkName`, it will be cancelled and the new work will run. `KEEP` will run the new OneTimeWorkRequests only if there is no pending work labelled with `uniqueWorkName`. `APPEND` will append the OneTimeWorkRequests as leaf nodes labelled with `uniqueWorkName`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the enqueue has completed |

### getLastCancelAllTimeMillis

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

```
abstract fun getLastCancelAllTimeMillis(): ListenableFuture<Long>
```

Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the last time all work was cancelled. This method is intended for use by library and module developers who have dependent data in their own repository that must be updated or deleted in case someone cancels their work without their prior knowledge.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the timestamp (`System#getCurrentTimeMillis()`) when `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#cancelAllWork()` was last invoked; this timestamp may be `0L` if this never occurred |

### getLastCancelAllTimeMillisLiveData

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

```
abstract fun getLastCancelAllTimeMillisLiveData(): LiveData<Long>
```

Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the last time all work was cancelled. This method is intended for use by library and module developers who have dependent data in their own repository that must be updated or deleted in case someone cancels their work without their prior knowledge.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the timestamp (`System#getCurrentTimeMillis()`) when `https://developer.android.com/reference/kotlin/androidx/work/WorkManager#cancelAllWork()` was last invoked; this timestamp may be `0L` if this never occurred |

### getWorkInfoById

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

```
abstract fun getWorkInfoById(id: UUID): ListenableFuture<WorkInfo?>
```

Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for a given work id.

| Parameters |
|---|---|
| `id: https://developer.android.com/reference/java/util/UUID.html` | The id of the work |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo?>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` associated with `id`; note that this `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` may be `null` if `id` is not known to WorkManager |

### getWorkInfoByIdFlow

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

```
abstract fun getWorkInfoByIdFlow(id: UUID): Flow<WorkInfo?>
```

Gets a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for a given work id.

| Parameters |
|---|---|
| `id: https://developer.android.com/reference/java/util/UUID.html` | The id of the work |

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo?>` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` associated with `id`; note that this `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` may be `null` if `id` is not known to WorkManager. |

### getWorkInfoByIdLiveData

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

```
abstract fun getWorkInfoByIdLiveData(id: UUID): LiveData<WorkInfo?>
```

Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for a given work id.

| Parameters |
|---|---|
| `id: https://developer.android.com/reference/java/util/UUID.html` | The id of the work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo?>` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` associated with `id`; note that this `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` may be `null` if `id` is not known to WorkManager. |

### getWorkInfos

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

```
abstract fun getWorkInfos(workQuery: WorkQuery): ListenableFuture<List<WorkInfo>>
```

Gets the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work referenced by the `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` specification.

| Parameters |
|---|---|
| `workQuery: https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` | The work query specification |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work referenced by this `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery`. |

### getWorkInfosByTag

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

```
abstract fun getWorkInfosByTag(tag: String): ListenableFuture<List<WorkInfo>>
```

Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work for a given tag.

| Parameters |
|---|---|
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tag of the work |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` list of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work tagged with `tag` |

### getWorkInfosByTagFlow

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

```
abstract fun getWorkInfosByTagFlow(tag: String): Flow<List<WorkInfo>>
```

Gets a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work for a given tag.

| Parameters |
|---|---|
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tag of the work |

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` list of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work tagged with `tag` |

### getWorkInfosByTagLiveData

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

```
abstract fun getWorkInfosByTagLiveData(tag: String): LiveData<List<WorkInfo>>
```

Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work for a given tag.

| Parameters |
|---|---|
| `tag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The tag of the work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` list of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work tagged with `tag` |

### getWorkInfosFlow

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

```
abstract fun getWorkInfosFlow(workQuery: WorkQuery): Flow<List<WorkInfo>>
```

Gets the `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work referenced by the `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` specification.

| Parameters |
|---|---|
| `workQuery: https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` | The work query specification |

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work referenced by this `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery`. |

### getWorkInfosForUniqueWork

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

```
abstract fun getWorkInfosForUniqueWork(uniqueWorkName: String): ListenableFuture<List<WorkInfo>>
```

Gets a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work in a work chain with a given unique name.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The unique name used to identify the chain of work |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work in the chain named `uniqueWorkName` |

### getWorkInfosForUniqueWorkFlow

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

```
abstract fun getWorkInfosForUniqueWorkFlow(uniqueWorkName: String): Flow<List<WorkInfo>>
```

Gets a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work in a work chain with a given unique name.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The unique name used to identify the chain of work |

| Returns |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work in the chain named `uniqueWorkName` |

### getWorkInfosForUniqueWorkLiveData

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

```
abstract fun getWorkInfosForUniqueWorkLiveData(uniqueWorkName: String): LiveData<List<WorkInfo>>
```

Gets a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work in a work chain with a given unique name.

| Parameters |
|---|---|
| `uniqueWorkName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The unique name used to identify the chain of work |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work in the chain named `uniqueWorkName` |

### getWorkInfosLiveData

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

```
abstract fun getWorkInfosLiveData(workQuery: WorkQuery): LiveData<List<WorkInfo>>
```

Gets the `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for all work referenced by the `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` specification.

| Parameters |
|---|---|
| `workQuery: https://developer.android.com/reference/kotlin/androidx/work/WorkQuery` | The work query specification |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/work/WorkInfo>>` | A `https://developer.android.com/reference/kotlin/androidx/lifecycle/LiveData` of the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html` of `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` for work referenced by this `https://developer.android.com/reference/kotlin/androidx/work/WorkQuery`. |

### pruneWork

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

```
abstract fun pruneWork(): Operation
```

Prunes all eligible finished work from the internal database. Eligible work must be finished (`https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State#SUCCEEDED`, `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State#FAILED`, or `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo.State#CANCELLED`), with zero unfinished dependents.

**Use this method with caution** ; by invoking it, you (and any modules and libraries in your codebase) will no longer be able to observe the `https://developer.android.com/reference/kotlin/androidx/work/WorkInfo` of the pruned work. You do not normally need to call this method - WorkManager takes care to auto-prune its work after a sane period of time. This method also ignores the `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest.Builder#keepResultsForAtLeast(kotlin.Long,java.util.concurrent.TimeUnit)` policy.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Operation` | An `https://developer.android.com/reference/kotlin/androidx/work/Operation` that can be used to determine when the pruneWork has completed |

### updateWork

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

```
abstract fun updateWork(request: WorkRequest): ListenableFuture<WorkManager.UpdateResult>
```

Updates the work with the new specification. A `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` passed as parameter must have an id set with `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest.Builder#setId(java.util.UUID)` that matches an id of the previously enqueued work.

It preserves enqueue time, e.g. if a work was enqueued 3 hours ago and had 6 hours long initial delay, after the update it would be still eligible for run in 3 hours, assuming that initial delay wasn't updated.

If the work being updated is currently running the returned ListenableFuture will be completed with `https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult#APPLIED_FOR_NEXT_RUN`. In this case the current run won't be interrupted and will continue to rely on previous state of the request, e.g. using old constraints, tags etc. However, on the next run, e.g. retry of one-time Worker or another iteration of periodic worker, the new worker specification will be used.

If the one time work that is updated is already finished the returned ListenableFuture will be completed with `https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult#NOT_APPLIED`.

If update can be applied immediately, e.g. the updated work isn't currently running, the returned ListenableFuture will be completed with `https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult#APPLIED_IMMEDIATELY`.

If the work with the given id (`request.getId()`) doesn't exist the returned ListenableFuture will be completed exceptionally with `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

Worker type can't be changed, `https://developer.android.com/reference/kotlin/androidx/work/OneTimeWorkRequest` can't be updated to `https://developer.android.com/reference/kotlin/androidx/work/PeriodicWorkRequest` and otherwise, the returned ListenableFuture will be completed with `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

| Parameters |
|---|---|
| `request: https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` | the new specification for the work. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/work/WorkManager.UpdateResult>` | a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` that will be successfully completed if the update was successful. The future will be completed with an exception if the work is already running or finished. |

## Public properties

### configuration

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

```
abstract val configuration: Configuration
```

The `https://developer.android.com/reference/kotlin/androidx/work/Configuration` instance that `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` was initialized with.