public final class

PeriodicWorkRequest.Builder

extends WorkRequest.Builder<PeriodicWorkRequest.Builder, PeriodicWorkRequest>

 java.lang.Object

androidx.work.WorkRequest.Builder<PeriodicWorkRequest.Builder, PeriodicWorkRequest>

↳androidx.work.PeriodicWorkRequest.Builder

Overview

Builder for PeriodicWorkRequests.

Summary

Constructors
publicBuilder(java.lang.Class<ListenableWorker> workerClass, java.time.Duration repeatInterval)

Creates a PeriodicWorkRequest to run periodically once every interval period.

publicBuilder(java.lang.Class<ListenableWorker> workerClass, java.time.Duration repeatInterval, java.time.Duration flexInterval)

Creates a PeriodicWorkRequest to run periodically once within the flex period of every interval period.

publicBuilder(java.lang.Class<ListenableWorker> workerClass, long repeatInterval, java.util.concurrent.TimeUnit repeatIntervalTimeUnit)

Creates a PeriodicWorkRequest to run periodically once every interval period.

publicBuilder(java.lang.Class<ListenableWorker> workerClass, long repeatInterval, java.util.concurrent.TimeUnit repeatIntervalTimeUnit, long flexInterval, java.util.concurrent.TimeUnit flexIntervalTimeUnit)

Creates a PeriodicWorkRequest to run periodically once within the flex period of every interval period.

Methods
from WorkRequest.Builder<B, W>addTag, build, keepResultsForAtLeast, keepResultsForAtLeast, setBackoffCriteria, setBackoffCriteria, setConstraints, setExpedited, setInitialDelay, setInitialDelay, setInitialRunAttemptCount, setInitialState, setInputData, setLastEnqueueTime, setScheduleRequestedAt
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(java.lang.Class<ListenableWorker> workerClass, long repeatInterval, java.util.concurrent.TimeUnit repeatIntervalTimeUnit)

Creates a PeriodicWorkRequest to run periodically once every interval period. The PeriodicWorkRequest is guaranteed to run exactly one time during this interval (subject to OS battery optimizations, such as doze mode). The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS. It may run immediately, at the end of the period, or any time in between so long as the other conditions are satisfied at the time. The run time of the PeriodicWorkRequest can be restricted to a flex period within an interval (see #Builder(Class, long, TimeUnit, long, TimeUnit)).

Parameters:

workerClass: The ListenableWorker class to run for this work
repeatInterval: The repeat interval in repeatIntervalTimeUnit units
repeatIntervalTimeUnit: The java.util.concurrent.TimeUnit for repeatInterval

public Builder(java.lang.Class<ListenableWorker> workerClass, java.time.Duration repeatInterval)

Creates a PeriodicWorkRequest to run periodically once every interval period. The PeriodicWorkRequest is guaranteed to run exactly one time during this interval (subject to OS battery optimizations, such as doze mode). The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS. It may run immediately, at the end of the period, or any time in between so long as the other conditions are satisfied at the time. The run time of the PeriodicWorkRequest can be restricted to a flex period within an interval (see #Builder(Class, Duration, Duration)).

Parameters:

workerClass: The ListenableWorker class to run for this work
repeatInterval: The repeat interval

public Builder(java.lang.Class<ListenableWorker> workerClass, long repeatInterval, java.util.concurrent.TimeUnit repeatIntervalTimeUnit, long flexInterval, java.util.concurrent.TimeUnit flexIntervalTimeUnit)

Creates a PeriodicWorkRequest to run periodically once within the flex period of every interval period. See diagram below. The flex period begins at repeatInterval - flexInterval to the end of the interval. The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.

 [     before flex     |     flex     ][     before flex     |     flex     ]...
 [   cannot run work   | can run work ][   cannot run work   | can run work ]...
 \____________________________________/\____________________________________/...
                interval 1                            interval 2             ...(repeat)
 

Parameters:

workerClass: The ListenableWorker class to run for this work
repeatInterval: The repeat interval in repeatIntervalTimeUnit units
repeatIntervalTimeUnit: The java.util.concurrent.TimeUnit for repeatInterval
flexInterval: The duration in flexIntervalTimeUnit units for which this work repeats from the end of the repeatInterval
flexIntervalTimeUnit: The java.util.concurrent.TimeUnit for flexInterval

public Builder(java.lang.Class<ListenableWorker> workerClass, java.time.Duration repeatInterval, java.time.Duration flexInterval)

Creates a PeriodicWorkRequest to run periodically once within the flex period of every interval period. See diagram below. The flex period begins at repeatInterval - flexInterval to the end of the interval. The repeat interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and the flex interval must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_FLEX_MILLIS.

 [     before flex     |     flex     ][     before flex     |     flex     ]...
 [   cannot run work   | can run work ][   cannot run work   | can run work ]...
 \____________________________________/\____________________________________/...
                interval 1                            interval 2             ...(repeat)
 

Parameters:

workerClass: The ListenableWorker class to run for this work
repeatInterval: The repeat interval
flexInterval: The duration in for which this work repeats from the end of the repeatInterval