# ExistingPeriodicWorkPolicy

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

*** ** * ** ***


```
public enum ExistingPeriodicWorkPolicy extends Enum<@NonNull ExistingPeriodicWorkPolicy>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [kotlin.Enum](https://developer.android.com/reference/java/lang/Enum.html)\<@[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull) [ExistingPeriodicWorkPolicy](https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy)\> ||
|   | ↳ | [androidx.work.ExistingPeriodicWorkPolicy](https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy) |

*** ** * ** ***

An enumeration of the conflict resolution policies available to unique `https://developer.android.com/reference/androidx/work/PeriodicWorkRequest`s in case of a collision.

## Summary

| ### Enum Values |
|---|---|
| `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#CANCEL_AND_REENQUEUE` | If there is existing pending (uncompleted) work with the same unique name, cancel and delete it. |
| `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#KEEP` | If there is existing pending (uncompleted) work with the same unique name, do nothing. |
| `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#REPLACE` | **This enum value is deprecated.** Deprecated in favor of the UPDATE policy. |
| `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#UPDATE` | If there is existing pending (uncompleted) work with the same unique name, it will be updated with the new specification. |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.enums/-enum-entries/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy>` | `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#getEntries()()` Returns an immutable `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.enums/-enum-entries/index.html` list containing the constants of this enum type, in the order they're declared. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy` | `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#valueOf(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html value)` Returns the enum constant of this type with the specified name. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull ExistingPeriodicWorkPolicy[]` | `https://developer.android.com/reference/androidx/work/ExistingPeriodicWorkPolicy#values()()` 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 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 `https://developer.android.com/reference/androidx/work/WorkManager#cancelWorkById(java.util.UUID)` or similar), it will be deleted and then the newly-specified work will be enqueued.

## Public methods

### getEntries

```
public final @NonNull EnumEntries<@NonNull ExistingPeriodicWorkPolicy> getEntries()
```

Returns an immutable `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.enums/-enum-entries/index.html` list containing the constants of this enum type, in the order they're declared.

### valueOf

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

```
public static 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 |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this enum type has no constant with the specified name |

### values

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

```
public static 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.

The function returns a new instance of the array on every call. The array could be mutated, so working with it may also require defensive copying. Consider using `entries` property as a more efficient alternative returning an immutable list of enum entries.