ExistingPeriodicWorkPolicy

public enum ExistingPeriodicWorkPolicy extends 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 the new specification.

Public methods

final @NonNull ExistingPeriodicWorkPolicy

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

final @NonNull ExistingPeriodicWorkPolicy[]

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

Enum Values

CANCEL_AND_REENQUEUE

ExistingPeriodicWorkPolicy ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE

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

ExistingPeriodicWorkPolicy ExistingPeriodicWorkPolicy.KEEP

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

REPLACE

ExistingPeriodicWorkPolicy ExistingPeriodicWorkPolicy.REPLACE

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

UPDATE

ExistingPeriodicWorkPolicy ExistingPeriodicWorkPolicy.UPDATE

If there is existing pending (uncompleted) work with the same unique name, it will be updated 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 methods

valueOf

Added in 1.0.0
public final @NonNull ExistingPeriodicWorkPolicy valueOf(@NonNull String value)

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
public final @NonNull ExistingPeriodicWorkPolicy[] values()

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.