ExistingPeriodicWorkPolicy


enum ExistingPeriodicWorkPolicy : Enum


An enumeration of the conflict resolution policies available to unique PeriodicWorkRequests in case of a collision.

Summary

Enum Values

CANCEL_AND_REENQUEUE

If there is existing pending (uncompleted) work with the same unique name, cancel and delete it.

KEEP

If there is existing pending (uncompleted) work with the same unique name, do nothing.

REPLACE

This enum value is deprecated. Deprecated in favor of the UPDATE policy.

UPDATE

If there is existing pending (uncompleted) work with the same unique name, it will be updated with the new specification.

Public functions

ExistingPeriodicWorkPolicy
valueOf(value: String)

Returns the enum constant of this type with the specified name.

Array<ExistingPeriodicWorkPolicy>

Returns an array containing the constants of this enum type, in the order they're declared.

Public properties

EnumEntries<ExistingPeriodicWorkPolicy>

Returns a representation of an immutable list of all enum entries, in the order they're declared.

Enum Values

CANCEL_AND_REENQUEUE

val ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUEExistingPeriodicWorkPolicy

If there is existing pending (uncompleted) work with the same unique name, cancel and delete it. Then, insert the newly-specified work.

It is identical for REPLACE. But for readability reasons it is better to use CANCEL_AND_REENQUEUE, because for a reader the difference between REPLACE vs UPDATED is unclear.

KEEP

val ExistingPeriodicWorkPolicy.KEEPExistingPeriodicWorkPolicy

If there is existing pending (uncompleted) work with the same unique name, do nothing. Otherwise, insert the newly-specified work.

REPLACE

val ExistingPeriodicWorkPolicy.REPLACEExistingPeriodicWorkPolicy

If there is existing pending (uncompleted) work with the same unique name, cancel and delete it. Then, insert the newly-specified work.

UPDATE

val ExistingPeriodicWorkPolicy.UPDATEExistingPeriodicWorkPolicy

If there is existing pending (uncompleted) work with the same unique name, it will be updated with the new specification. Otherwise, new work with the given name will be enqueued.

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

If the work being updated is currently running, 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 iteration of periodic worker, the new worker specification will be used.

If the work was previously cancelled (via WorkManager.cancelWorkById or similar), it will be deleted and then the newly-specified work will be enqueued.

Public functions

valueOf

Added in 1.0.0
fun valueOf(value: String): ExistingPeriodicWorkPolicy

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Throws
kotlin.IllegalArgumentException

if this enum type has no constant with the specified name

values

Added in 1.0.0
fun values(): Array<ExistingPeriodicWorkPolicy>

Returns an array containing the constants of this enum type, in the order they're declared.

This method may be used to iterate over the constants.

Public properties

entries

val entriesEnumEntries<ExistingPeriodicWorkPolicy>

Returns a representation of an immutable list of all enum entries, in the order they're declared.

This method may be used to iterate over the enum entries.