PeriodicWorkRequest
public
final
class
PeriodicWorkRequest
extends WorkRequest
| java.lang.Object | ||
| ↳ | androidx.work.WorkRequest | |
| ↳ | androidx.work.PeriodicWorkRequest | |
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#Builder for documentation on flexIntervals.
Periodic work has a minimum interval of 15 minutes and it cannot have an initial delay.
Periodic work is intended for use cases where you want a fairly consistent delay between consecutive runs, and you are willing to tolerate drift. For example, periodic work that runs every 24 hours, may exhibit the following drift because of OS battery optimizations:
Iteration | Execution Time
----------+------------------
1 | Jan 01, 06:00 AM
2 | Jan 02, 06:24 AM
3 | Jan 03, 07:15 AM
4 | Jan 04, 08:00 AM
5 | Jan 05, 08:00 AM
6 | Jan 06, 08:02 AM
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
WorkRequest.Builder.setBackoffCriteria(BackoffPolicy, long, TimeUnit).
Periodic work cannot be part of a chain or graph of work.
Summary
Nested classes | |
|---|---|
class |
PeriodicWorkRequest.Builder
Builder for |
Constants | |
|---|---|
long |
MIN_PERIODIC_FLEX_MILLIS
The minimum flex duration for |
long |
MIN_PERIODIC_INTERVAL_MILLIS
The minimum interval duration for |
Inherited constants |
|---|
Inherited methods | |
|---|---|
Constants
MIN_PERIODIC_FLEX_MILLIS
public static final long MIN_PERIODIC_FLEX_MILLIS
The minimum flex duration for PeriodicWorkRequest (in milliseconds).
Constant Value: 300000 (0x00000000000493e0)
MIN_PERIODIC_INTERVAL_MILLIS
public static final long MIN_PERIODIC_INTERVAL_MILLIS
The minimum interval duration for PeriodicWorkRequest (in milliseconds).
Constant Value: 900000 (0x00000000000dbba0)
Interfaces
Classes
- ArrayCreatingInputMerger
- Configuration
- Configuration.Builder
- Constraints
- Constraints.Builder
- Data
- Data.Builder
- InputMerger
- ListenableWorker
- ListenableWorker.Result
- OneTimeWorkRequest
- OneTimeWorkRequest.Builder
- Operation.State
- Operation.State.FAILURE
- Operation.State.IN_PROGRESS
- Operation.State.SUCCESS
- OverwritingInputMerger
- PeriodicWorkRequest
- PeriodicWorkRequest.Builder
- RxWorker
- WorkContinuation
- Worker
- WorkerFactory
- WorkerParameters
- WorkInfo
- WorkManager
- WorkRequest
- WorkRequest.Builder
Enums
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.