PeriodicWorkRequest


public final class PeriodicWorkRequest extends WorkRequest


A WorkRequest for repeating work. This work executes multiple times until it is cancelled, with the first execution happening immediately or as soon as the given Constraints are met. The next execution will happen during the period interval; note that execution may be delayed because WorkManager is subject to OS battery optimizations, such as doze mode.

You can control when the work executes in the period interval more exactly - see PeriodicWorkRequest.Builder for documentation on flexIntervals.

Periodic work has a minimum interval of 15 minutes.

Periodic work is intended for use cases where you want a fairly consistent delay between consecutive runs, and you are willing to accept inexactness due to battery optimizations and doze mode. Please note that if your periodic work has constraints, it will not execute until the constraints are met, even if the delay between periods has been met.

If you need to schedule work that happens exactly at a certain time or only during a certain time window, you should consider using OneTimeWorkRequests.

The normal lifecycle of a PeriodicWorkRequest is ENQUEUED -> RUNNING -> ENQUEUED. By definition, periodic work cannot terminate in a succeeded or failed state, since it must recur. It can only terminate if explicitly cancelled. However, in the case of retries, periodic work will still back off according to PeriodicWorkRequest.Builder.setBackoffCriteria.

Periodic work cannot be part of a chain or graph of work.

Summary

Nested types

Builder for PeriodicWorkRequests.

Constants

static final long

The minimum flex duration for PeriodicWorkRequest (in milliseconds).

static final long

The minimum interval duration for PeriodicWorkRequest (in milliseconds).

Inherited methods

From androidx.work.WorkRequest
@NonNull UUID

The unique identifier associated with this unit of work.

Constants

MIN_PERIODIC_FLEX_MILLIS

public static final long MIN_PERIODIC_FLEX_MILLIS

The minimum flex duration for PeriodicWorkRequest (in milliseconds).

MIN_PERIODIC_INTERVAL_MILLIS

public static final long MIN_PERIODIC_INTERVAL_MILLIS

The minimum interval duration for PeriodicWorkRequest (in milliseconds).