# WorkInfo

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

*** ** * ** ***


```
public final class WorkInfo
```

<br />

*** ** * ** ***

Information about a particular `https://developer.android.com/reference/androidx/work/WorkRequest` containing the id of the WorkRequest, its current `https://developer.android.com/reference/androidx/work/WorkInfo.State`, output, tags, and run attempt count. Note that output is only available for the terminal states (`https://developer.android.com/reference/androidx/work/WorkInfo.State#SUCCEEDED` and `https://developer.android.com/reference/androidx/work/WorkInfo.State#FAILED`).

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/work/WorkInfo.PeriodicityInfo` A periodic work's interval and flex duration |
| `public enum https://developer.android.com/reference/androidx/work/WorkInfo.State extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State>` The current lifecycle state of a `https://developer.android.com/reference/androidx/work/WorkRequest`. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_APP_STANDBY() = 12` The current standby bucket requires that the job stop now. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_BACKGROUND_RESTRICTION() = 11` The app is restricted from running in the background. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_CANCELLED_BY_APP() = 1` The worker was cancelled directly by the app, either by calling cancel methods, e.g. `https://developer.android.com/reference/androidx/work/WorkManager#cancelUniqueWork(kotlin.String)`, or enqueueing uniquely named worker with a policy that cancels an existing worker, e.g. `https://developer.android.com/reference/androidx/work/ExistingWorkPolicy#REPLACE`. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW() = 5` The requested battery-not-low constraint is no longer satisfied. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_CONSTRAINT_CHARGING() = 6` The requested charging constraint is no longer satisfied. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_CONSTRAINT_CONNECTIVITY() = 7` The requested connectivity constraint is no longer satisfied. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_CONSTRAINT_DEVICE_IDLE() = 8` The requested idle constraint is no longer satisfied. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW() = 9` The requested storage-not-low constraint is no longer satisfied. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_DEVICE_STATE() = 4` The device state (eg. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED() = 15` The system's estimate of when the app will be launched changed significantly enough to decide this worker shouldn't be running right now. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_FOREGROUND_SERVICE_TIMEOUT()` The foreground worker used up its maximum execution time and timed out. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_NOT_STOPPED()` Additional stop reason, that is returned from `https://developer.android.com/reference/androidx/work/WorkInfo#stopReason()` in cases when a worker in question wasn't stopped. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_PREEMPT() = 2` The job was stopped to run a higher priority job of the app. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_QUOTA() = 10` The app has consumed all of its current quota. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_SYSTEM_PROCESSING() = 14` The system is doing some processing that requires stopping this job. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_TIMEOUT() = 3` The worker used up its maximum execution time and timed out. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_UNKNOWN()` Stop reason that is used in cases when worker did stop, but the reason for this is unknown. |
| `static final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_USER() = 13` The user stopped the job. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/work/WorkInfo#WorkInfo(java.util.UUID,androidx.work.WorkInfo.State,kotlin.collections.Set,androidx.work.Data,androidx.work.Data,kotlin.Int,kotlin.Int,androidx.work.Constraints,kotlin.Long,androidx.work.WorkInfo.PeriodicityInfo,kotlin.Long,kotlin.Int,kotlin.String)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html id, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State state, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html> tags, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Data outputData, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Data progress, int runAttemptCount, int generation, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints constraints, long initialDelayMillis, https://developer.android.com/reference/androidx/work/WorkInfo.PeriodicityInfo periodicityInfo, long nextScheduleTimeMillis, int stopReason, https://developer.android.com/reference/java/lang/String.html workerClassName )` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/work/WorkInfo#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Constraints` | `https://developer.android.com/reference/androidx/work/WorkInfo#getConstraints()()` `https://developer.android.com/reference/androidx/work/Constraints` of this worker. |
| `final int` | `https://developer.android.com/reference/androidx/work/WorkInfo#getGeneration()()` The latest generation of this Worker. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/UUID.html` | `https://developer.android.com/reference/androidx/work/WorkInfo#getId()()` The identifier of the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final long` | `https://developer.android.com/reference/androidx/work/WorkInfo#getInitialDelayMillis()()` The initial delay for this work set in the `https://developer.android.com/reference/androidx/work/WorkRequest` |
| `final long` | `https://developer.android.com/reference/androidx/work/WorkInfo#getNextScheduleTimeMillis()()` The earliest time this work is eligible to run next, if this work is `https://developer.android.com/reference/androidx/work/WorkInfo.State#ENQUEUED`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Data` | `https://developer.android.com/reference/androidx/work/WorkInfo#getOutputData()()` The output `https://developer.android.com/reference/androidx/work/Data` for the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final https://developer.android.com/reference/androidx/work/WorkInfo.PeriodicityInfo` | `https://developer.android.com/reference/androidx/work/WorkInfo#getPeriodicityInfo()()` For periodic work, the period and flex duration set in the `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Data` | `https://developer.android.com/reference/androidx/work/WorkInfo#getProgress()()` The progress `https://developer.android.com/reference/androidx/work/Data` associated with the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` | `https://developer.android.com/reference/androidx/work/WorkInfo#getRunAttemptCount()()` The run attempt count of the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkInfo.State` | `https://developer.android.com/reference/androidx/work/WorkInfo#getState()()` The current `https://developer.android.com/reference/androidx/work/WorkInfo.State` of the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final int` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/androidx/work/WorkInfo#getStopReason()()` The reason why this worker was stopped on the previous run attempt. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html>` | `https://developer.android.com/reference/androidx/work/WorkInfo#getTags()()` The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html` of tags associated with the `https://developer.android.com/reference/androidx/work/WorkRequest`. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/work/WorkInfo#getWorkerClassName()()` The worker class specified when the work request was enqueued. |
| `int` | `https://developer.android.com/reference/androidx/work/WorkInfo#hashCode()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/work/WorkInfo#toString()()` |

## Constants

### STOP_REASON_APP_STANDBY

```
public static final int STOP_REASON_APP_STANDBY = 12
```

The current standby bucket requires that the job stop now.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobParameters.html#STOP_REASON_APP_STANDBY` |   |

### STOP_REASON_BACKGROUND_RESTRICTION

```
public static final int STOP_REASON_BACKGROUND_RESTRICTION = 11
```

The app is restricted from running in the background.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobParameters.html#STOP_REASON_BACKGROUND_RESTRICTION` |   |

### STOP_REASON_CANCELLED_BY_APP

```
public static final int STOP_REASON_CANCELLED_BY_APP = 1
```

The worker was cancelled directly by the app, either by calling cancel methods, e.g. `https://developer.android.com/reference/androidx/work/WorkManager#cancelUniqueWork(kotlin.String)`, or enqueueing uniquely named worker with a policy that cancels an existing worker, e.g. `https://developer.android.com/reference/androidx/work/ExistingWorkPolicy#REPLACE`.

### STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW

```
public static final int STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW = 5
```

The requested battery-not-low constraint is no longer satisfied.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiresBatteryNotLow(boolean)` |   |

### STOP_REASON_CONSTRAINT_CHARGING

```
public static final int STOP_REASON_CONSTRAINT_CHARGING = 6
```

The requested charging constraint is no longer satisfied.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#setRequiresCharging(boolean)` |   |

### STOP_REASON_CONSTRAINT_CONNECTIVITY

```
public static final int STOP_REASON_CONSTRAINT_CONNECTIVITY = 7
```

The requested connectivity constraint is no longer satisfied.

### STOP_REASON_CONSTRAINT_DEVICE_IDLE

```
public static final int STOP_REASON_CONSTRAINT_DEVICE_IDLE = 8
```

The requested idle constraint is no longer satisfied.

### STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW

```
public static final int STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW = 9
```

The requested storage-not-low constraint is no longer satisfied.

### STOP_REASON_DEVICE_STATE

```
public static final int STOP_REASON_DEVICE_STATE = 4
```

The device state (eg. Doze, battery saver, memory usage, etc) requires WorkManager to stop this worker.

### STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED

```
public static final int STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED = 15
```

The system's estimate of when the app will be launched changed significantly enough to decide this worker shouldn't be running right now.

### STOP_REASON_FOREGROUND_SERVICE_TIMEOUT

```
public static final int STOP_REASON_FOREGROUND_SERVICE_TIMEOUT
```

The foreground worker used up its maximum execution time and timed out.

Foreground workers have a maximum execution time limit depending on the `https://developer.android.com/reference/androidx/work/ForegroundInfo` type. See the notes on `https://developer.android.com/reference/android/content/pm/ServiceInfo.html` types.

### STOP_REASON_NOT_STOPPED

```
public static final int STOP_REASON_NOT_STOPPED
```

Additional stop reason, that is returned from `https://developer.android.com/reference/androidx/work/WorkInfo#stopReason()` in cases when a worker in question wasn't stopped. E.g. when a worker was just enqueued, but didn't run yet.

### STOP_REASON_PREEMPT

```
public static final int STOP_REASON_PREEMPT = 2
```

The job was stopped to run a higher priority job of the app.

### STOP_REASON_QUOTA

```
public static final int STOP_REASON_QUOTA = 10
```

The app has consumed all of its current quota. Each app is assigned a quota of how much it can run workers within a certain time frame. The quota is informed, in part, by app standby buckets.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobParameters.html#STOP_REASON_QUOTA` |   |

### STOP_REASON_SYSTEM_PROCESSING

```
public static final int STOP_REASON_SYSTEM_PROCESSING = 14
```

The system is doing some processing that requires stopping this job.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobParameters.html#STOP_REASON_SYSTEM_PROCESSING` |   |

### STOP_REASON_TIMEOUT

```
public static final int STOP_REASON_TIMEOUT = 3
```

The worker used up its maximum execution time and timed out. Each individual worker has a maximum execution time limit, regardless of how much total quota the app has. See the note on `https://developer.android.com/reference/android/app/job/JobScheduler.html` for the execution time limits.

### STOP_REASON_UNKNOWN

```
public static final int STOP_REASON_UNKNOWN
```

Stop reason that is used in cases when worker did stop, but the reason for this is unknown. For example, when the app abruptly stopped due to a crash or when a device suddenly ran out of the battery.

### STOP_REASON_USER

```
public static final int STOP_REASON_USER = 13
```

The user stopped the job. This can happen either through force-stop, adb shell commands, uninstalling, or some other UI.

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/job/JobParameters.html#STOP_REASON_USER` |   |

## Public constructors

### WorkInfo

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

```
public WorkInfo(
    @NonNull UUID id,
    @NonNull WorkInfo.State state,
    @NonNull Set<@NonNull String> tags,
    @NonNull Data outputData,
    @NonNull Data progress,
    int runAttemptCount,
    int generation,
    @NonNull Constraints constraints,
    long initialDelayMillis,
    WorkInfo.PeriodicityInfo periodicityInfo,
    long nextScheduleTimeMillis,
    int stopReason,
    String workerClassName
)
```

## Public methods

### equals

```
public boolean equals(Object other)
```

### getConstraints

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

```
public final @NonNull Constraints getConstraints()
```

`https://developer.android.com/reference/androidx/work/Constraints` of this worker.

### getGeneration

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

```
public final int getGeneration()
```

The latest generation of this Worker.

A work has multiple generations, if it was updated via `https://developer.android.com/reference/androidx/work/WorkManager#updateWork(androidx.work.WorkRequest)` or `https://developer.android.com/reference/androidx/work/WorkManager#enqueueUniquePeriodicWork(kotlin.String,androidx.work.ExistingPeriodicWorkPolicy,androidx.work.PeriodicWorkRequest)` using `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#UPDATE`.

If this worker is currently running, it can possibly be of an older generation rather than returned by this function if an update has happened during an execution of this worker.

### getId

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

```
public final @NonNull UUID getId()
```

The identifier of the `https://developer.android.com/reference/androidx/work/WorkRequest`.

### getInitialDelayMillis

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

```
public final long getInitialDelayMillis()
```

The initial delay for this work set in the `https://developer.android.com/reference/androidx/work/WorkRequest`

### getNextScheduleTimeMillis

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

```
public final long getNextScheduleTimeMillis()
```

The earliest time this work is eligible to run next, if this work is `https://developer.android.com/reference/androidx/work/WorkInfo.State#ENQUEUED`.

This is the earliest `https://developer.android.com/reference/java/lang/System.html#currentTimeMillis()` time that WorkManager would consider running this work, regardless of any other system. It only represents the time that the initialDelay, periodic configuration, and backoff criteria are considered to be met.

Work will almost never run at this time in the real world. This method is intended for use in scheduling tests or to check set schedules in app. Work run times are dependent on many factors like the underlying system scheduler, doze and power saving modes of the OS, and meeting any configured constraints. This is expected and is not considered a bug.

The returned value may be in the past if the work was not able to run at that time. It will be eligible to run any time after that time.

Defaults to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/-companion/-m-a-x_-v-a-l-u-e.html` for all other states, including if the work is currently `https://developer.android.com/reference/androidx/work/WorkInfo.State#RUNNING` or `https://developer.android.com/reference/androidx/work/WorkInfo.State#BLOCKED` on prerequisite work.

Even if this value is set, the work may not be registered with the system scheduler if there are limited scheduling slots or other factors.

### getOutputData

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

```
public final @NonNull Data getOutputData()
```

The output `https://developer.android.com/reference/androidx/work/Data` for the `https://developer.android.com/reference/androidx/work/WorkRequest`. If the WorkRequest is unfinished, this is always `https://developer.android.com/reference/androidx/work/Data#EMPTY()`.

### getPeriodicityInfo

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

```
public final WorkInfo.PeriodicityInfo getPeriodicityInfo()
```

For periodic work, the period and flex duration set in the `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest`.

Null if this is onetime work.

### getProgress

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

```
public final @NonNull Data getProgress()
```

The progress `https://developer.android.com/reference/androidx/work/Data` associated with the `https://developer.android.com/reference/androidx/work/WorkRequest`.

### getRunAttemptCount

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

```
public final @IntRange(from = 0) int getRunAttemptCount()
```

The run attempt count of the `https://developer.android.com/reference/androidx/work/WorkRequest`. Note that for `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest`s, the run attempt count gets reset between successful runs.

### getState

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

```
public final @NonNull WorkInfo.State getState()
```

The current `https://developer.android.com/reference/androidx/work/WorkInfo.State` of the `https://developer.android.com/reference/androidx/work/WorkRequest`.

### getStopReason

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

```
@RequiresApi(value = 31)
public final int getStopReason()
```

The reason why this worker was stopped on the previous run attempt.

For a worker being stopped, at first it should have attempted to run, i.e. its state should be == RUNNING and then `https://developer.android.com/reference/androidx/work/ListenableWorker#onStopped()` should have been called, resulting in this worker's state going back `https://developer.android.com/reference/androidx/work/WorkInfo.State#ENQUEUED`. In this situation (`runAttemptCount > 0` and `state == ENQUEUED`) this `stopReason` property could be checked to see for additional information. Please note, that this state (`runAttemptCount > 0` and `state == ENQUEUED`) can happen not only because a worker was stopped, but also when a worker returns `ListenableWorker.Result.retry()`. In this situation this property will return `https://developer.android.com/reference/androidx/work/WorkInfo#STOP_REASON_NOT_STOPPED()`.

### getTags

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

```
public final @NonNull Set<@NonNull String> getTags()
```

The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html` of tags associated with the `https://developer.android.com/reference/androidx/work/WorkRequest`.

### getWorkerClassName

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

```
public final String getWorkerClassName()
```

The worker class specified when the work request was enqueued.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```