lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

PeriodicWorkRequest.Builder

public static final class PeriodicWorkRequest.Builder
extends Builder<PeriodicWorkRequest.BuilderPeriodicWorkRequest>

java.lang.Object
   ↳ androidx.work.WorkRequest.Builder<androidx.work.PeriodicWorkRequest.Builderandroidx.work.PeriodicWorkRequest>
     ↳ androidx.work.PeriodicWorkRequest.Builder


Builder for PeriodicWorkRequest class.

Summary

Public constructors

PeriodicWorkRequest.Builder(Class<? extends Worker> workerClass, long repeatInterval, TimeUnit repeatIntervalTimeUnit)

Creates a PeriodicWorkRequest to run periodically once every interval period.

PeriodicWorkRequest.Builder(Class<? extends Worker> workerClass, Duration repeatInterval)

Creates a PeriodicWorkRequest to run periodically once every interval period.

PeriodicWorkRequest.Builder(Class<? extends Worker> workerClass, long repeatInterval, TimeUnit repeatIntervalTimeUnit, long flexInterval, TimeUnit flexIntervalTimeUnit)

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

PeriodicWorkRequest.Builder(Class<? extends Worker> workerClass, Duration repeatInterval, Duration flexInterval)

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

Public methods

PeriodicWorkRequest build()

Builds this work object.

Inherited methods

Public constructors

PeriodicWorkRequest.Builder

public PeriodicWorkRequest.Builder (Class<? extends Worker> workerClass, 
                long repeatInterval, 
                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 intervalMillis 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.

Parameters
workerClass Class: The Worker class to run with this job

repeatInterval long: The repeat interval in repeatIntervalTimeUnit units

repeatIntervalTimeUnit TimeUnit: The TimeUnit for repeatInterval

PeriodicWorkRequest.Builder

public PeriodicWorkRequest.Builder (Class<? extends Worker> workerClass, 
                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 intervalMillis 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.

Parameters
workerClass Class: The Worker class to run with this job

repeatInterval Duration: The repeat interval

PeriodicWorkRequest.Builder

public PeriodicWorkRequest.Builder (Class<? extends Worker> workerClass, 
                long repeatInterval, 
                TimeUnit repeatIntervalTimeUnit, 
                long flexInterval, 
                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 intervalMillis - flexMillis to the end of the interval. intervalMillis must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and flexMillis 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 Class: The Worker class to run with this job

repeatInterval long: The repeat interval in repeatIntervalTimeUnit units

repeatIntervalTimeUnit TimeUnit: The TimeUnit for repeatInterval

flexInterval long: The duration in flexIntervalTimeUnit units for which this work repeats from the end of the repeatInterval

flexIntervalTimeUnit TimeUnit: The TimeUnit for flexInterval

PeriodicWorkRequest.Builder

public PeriodicWorkRequest.Builder (Class<? extends Worker> workerClass, 
                Duration repeatInterval, 
                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 intervalMillis - flexMillis to the end of the interval. intervalMillis must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS and flexMillis 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 Class: The Worker class to run with this job

repeatInterval Duration: The repeat interval

flexInterval Duration: The duration in for which this work repeats from the end of the repeatInterval

Public methods

build

public PeriodicWorkRequest build ()

Builds this work object.

Returns
PeriodicWorkRequest The concrete implementation of the work associated with this builder