WorkInfo


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

A periodic work's interval and flex duration

The current lifecycle state of a WorkRequest.

Constants

const Int

The current standby bucket requires that the job stop now.

const Int

The app is restricted from running in the background.

const Int

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

const Int

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

const Int

The requested charging constraint is no longer satisfied.

const Int

The requested connectivity constraint is no longer satisfied.

const Int

The requested idle constraint is no longer satisfied.

const Int

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

const Int

The device state (eg.

const 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.

const Int

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

const Int

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

const Int

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

const Int

The app has consumed all of its current quota.

const Int

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

const Int

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

const Int

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

const Int

The user stopped the job.

Public constructors

WorkInfo(
    id: UUID,
    state: WorkInfo.State,
    tags: Set<String>,
    outputData: Data,
    progress: Data,
    runAttemptCount: Int,
    generation: Int,
    constraints: Constraints,
    initialDelayMillis: Long,
    periodicityInfo: WorkInfo.PeriodicityInfo?,
    nextScheduleTimeMillis: Long,
    stopReason: Int
)

Public functions

open operator Boolean
equals(other: Any?)
open Int
open String

Public properties

Constraints

Constraints of this worker.

Int

The latest generation of this Worker.

UUID

The identifier of the WorkRequest.

Long

The initial delay for this work set in the WorkRequest

Long

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

Data

The output Data for the WorkRequest.

WorkInfo.PeriodicityInfo?

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

Data

The progress Data associated with the WorkRequest.

Int

The run attempt count of the WorkRequest.

WorkInfo.State

The current State of the WorkRequest.

Int

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

Set<String>

The Set of tags associated with the WorkRequest.

Constants

STOP_REASON_APP_STANDBY

const val STOP_REASON_APP_STANDBY = 12: Int

The current standby bucket requires that the job stop now.

STOP_REASON_BACKGROUND_RESTRICTION

const val STOP_REASON_BACKGROUND_RESTRICTION = 11: Int

The app is restricted from running in the background.

STOP_REASON_CANCELLED_BY_APP

const val STOP_REASON_CANCELLED_BY_APP = 1: Int

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

STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW

const val STOP_REASON_CONSTRAINT_BATTERY_NOT_LOW = 5: Int

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

STOP_REASON_CONSTRAINT_CHARGING

const val STOP_REASON_CONSTRAINT_CHARGING = 6: Int

The requested charging constraint is no longer satisfied.

STOP_REASON_CONSTRAINT_CONNECTIVITY

const val STOP_REASON_CONSTRAINT_CONNECTIVITY = 7: Int

The requested connectivity constraint is no longer satisfied.

STOP_REASON_CONSTRAINT_DEVICE_IDLE

const val STOP_REASON_CONSTRAINT_DEVICE_IDLE = 8: Int

The requested idle constraint is no longer satisfied.

STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW

const val STOP_REASON_CONSTRAINT_STORAGE_NOT_LOW = 9: Int

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

STOP_REASON_DEVICE_STATE

const val STOP_REASON_DEVICE_STATE = 4: Int

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

STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED

const val STOP_REASON_ESTIMATED_APP_LAUNCH_TIME_CHANGED = 15: 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.

STOP_REASON_FOREGROUND_SERVICE_TIMEOUT

const val STOP_REASON_FOREGROUND_SERVICE_TIMEOUTInt

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

Foreground workers have a maximum execution time limit depending on the ForegroundInfo type. See the notes on android.content.pm.ServiceInfo types.

STOP_REASON_NOT_STOPPED

const val STOP_REASON_NOT_STOPPEDInt

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

const val STOP_REASON_PREEMPT = 2: Int

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

STOP_REASON_QUOTA

const val STOP_REASON_QUOTA = 10: Int

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

const val STOP_REASON_SYSTEM_PROCESSING = 14: Int

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

STOP_REASON_TIMEOUT

const val STOP_REASON_TIMEOUT = 3: Int

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

const val STOP_REASON_UNKNOWNInt

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

const val STOP_REASON_USER = 13: Int

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
WorkInfo(
    id: UUID,
    state: WorkInfo.State,
    tags: Set<String>,
    outputData: Data = Data.EMPTY,
    progress: Data = Data.EMPTY,
    runAttemptCount: Int = 0,
    generation: Int = 0,
    constraints: Constraints = Constraints.NONE,
    initialDelayMillis: Long = 0,
    periodicityInfo: WorkInfo.PeriodicityInfo? = null,
    nextScheduleTimeMillis: Long = Long.MAX_VALUE,
    stopReason: Int = STOP_REASON_NOT_STOPPED
)

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

constraints

Added in 2.9.0
val constraintsConstraints

Constraints of this worker.

generation

Added in 2.8.0
val generationInt

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.

id

Added in 1.0.0
val idUUID

The identifier of the WorkRequest.

initialDelayMillis

Added in 2.9.0
val initialDelayMillisLong

The initial delay for this work set in the WorkRequest

nextScheduleTimeMillis

Added in 2.9.0
val nextScheduleTimeMillisLong

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.

outputData

Added in 1.0.0
val outputDataData

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

periodicityInfo

Added in 2.9.0
val periodicityInfoWorkInfo.PeriodicityInfo?

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

Null if this is onetime work.

progress

Added in 2.3.0
val progressData

The progress Data associated with the WorkRequest.

runAttemptCount

Added in 2.1.0
val runAttemptCountInt

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

state

Added in 1.0.0
val stateWorkInfo.State

The current State of the WorkRequest.

stopReason

Added in 2.9.0
val stopReasonInt

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.

tags

Added in 1.0.0
val tagsSet<String>

The Set of tags associated with the WorkRequest.