WorkInfo

public final class WorkInfo


Information about a particular WorkRequest containing the id of the WorkRequest, its current State, output, tags, and run attempt count. Note that output is only available for the terminal states (State.SUCCEEDED and State.FAILED).

Summary

Nested types

public final class WorkInfo.PeriodicityInfo

A periodic work's interval and flex duration

public enum WorkInfo.State extends Enum

The current lifecycle state of a WorkRequest.

Constants

static final int

The current standby bucket requires that the job stop now.

static final int

The app is restricted from running in the background.

static final int

The worker was cancelled directly by the app, either by calling cancel methods, e.g. WorkManager.cancelUniqueWork, or enqueueing uniquely named worker with with a policy that cancels an existing worker, e.g. ExistingWorkPolicy.REPLACE.

static final int

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

static final int

The requested charging constraint is no longer satisfied.

static final int

The requested connectivity constraint is no longer satisfied.

static final int

The requested idle constraint is no longer satisfied.

static final int

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

static final int

The device state (eg.

static final int

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

Additional stop reason, that is returned from WorkInfo.stopReason in cases when a worker in question wasn't stopped.

static final int

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

static final int

The app has consumed all of its current quota.

static final int

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

static final int

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

static final int

Stop reason that is used in cases when worker did stop, but the reason for this is unknown.

static final int

The user stopped the job.

Public constructors

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,
    @StopReason int stopReason
)

Public methods

boolean
equals(Object other)
final @NonNull Constraints

Constraints of this worker.

final int

The latest generation of this Worker.

final @NonNull UUID

The identifier of the WorkRequest.

final long

The initial delay for this work set in the WorkRequest

final long

The earliest time this work is eligible to run next, if this work is State.ENQUEUED.

final @NonNull Data

The output Data for the WorkRequest.

final WorkInfo.PeriodicityInfo

For periodic work, the period and flex duration set in the PeriodicWorkRequest.

final @NonNull Data

The progress Data associated with the WorkRequest.

final @IntRange(from = 0) int

The run attempt count of the WorkRequest.

final @NonNull WorkInfo.State

The current State of the WorkRequest.

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

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

final @NonNull Set<@NonNull String>

The Set of tags associated with the WorkRequest.

int
@NonNull String

Constants

STOP_REASON_APP_STANDBY

public static final int STOP_REASON_APP_STANDBY = 12

The current standby bucket requires that the job stop now.

STOP_REASON_BACKGROUND_RESTRICTION

public static final int STOP_REASON_BACKGROUND_RESTRICTION = 11

The app is restricted from running in the background.

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. WorkManager.cancelUniqueWork, or enqueueing uniquely named worker with with a policy that cancels an existing worker, e.g. 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.

STOP_REASON_CONSTRAINT_CHARGING

public static final int STOP_REASON_CONSTRAINT_CHARGING = 6

The requested charging constraint is no longer satisfied.

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_NOT_STOPPED

public static final int STOP_REASON_NOT_STOPPED

Additional stop reason, that is returned from 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.

STOP_REASON_SYSTEM_PROCESSING

public static final int STOP_REASON_SYSTEM_PROCESSING = 14

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

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 JobScheduler 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
STOP_REASON_USER

Public constructors

WorkInfo

Added in 2.9.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,
    @StopReason int stopReason
)

Public methods

equals

public boolean equals(Object other)

getConstraints

Added in 2.9.0
public final @NonNull Constraints getConstraints()

Constraints of this worker.

getGeneration

Added in 2.8.0
public final int getGeneration()

The latest generation of this Worker.

A work has multiple generations, if it was updated via WorkManager.updateWork or WorkManager.enqueueUniquePeriodicWork using 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
public final @NonNull UUID getId()

The identifier of the WorkRequest.

getInitialDelayMillis

Added in 2.9.0
public final long getInitialDelayMillis()

The initial delay for this work set in the WorkRequest

getNextScheduleTimeMillis

Added in 2.9.0
public final long getNextScheduleTimeMillis()

The earliest time this work is eligible to run next, if this work is State.ENQUEUED.

This is the earliest System.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 Long.MAX_VALUE for all other states, including if the work is currently State.RUNNING or 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
public final @NonNull Data getOutputData()

The output Data for the WorkRequest. If the WorkRequest is unfinished, this is always Data.EMPTY.

getPeriodicityInfo

Added in 2.9.0
public final WorkInfo.PeriodicityInfo getPeriodicityInfo()

For periodic work, the period and flex duration set in the PeriodicWorkRequest.

Null if this is onetime work.

getProgress

Added in 2.3.0
public final @NonNull Data getProgress()

The progress Data associated with the WorkRequest.

getRunAttemptCount

Added in 2.1.0
public final @IntRange(from = 0) int getRunAttemptCount()

The run attempt count of the WorkRequest. Note that for PeriodicWorkRequests, the run attempt count gets reset between successful runs.

getState

Added in 1.0.0
public final @NonNull WorkInfo.State getState()

The current State of the WorkRequest.

getStopReason

Added in 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 ListenableWorker.onStopped should have been called, resulting in this worker's state going back 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 STOP_REASON_NOT_STOPPED.

getTags

Added in 1.0.0
public final @NonNull Set<@NonNull StringgetTags()

The Set of tags associated with the WorkRequest.

hashCode

public int hashCode()

toString

public @NonNull String toString()