Configuration.Builder

public static final class Configuration.Builder
extends Object

java.lang.Object
   ↳ androidx.work.Configuration.Builder


A Builder for Configurations.

Summary

Public constructors

Configuration.Builder()

Public methods

Configuration build()

Builds a Configuration object.

Configuration.Builder setExecutor(Executor executor)

Specifies a custom Executor for WorkManager.

Configuration.Builder setJobSchedulerJobIdRange(int minJobSchedulerId, int maxJobSchedulerId)

Specifies the range of JobInfo IDs that can be used by WorkManager.

Configuration.Builder setMaxSchedulerLimit(int maxSchedulerLimit)

Specifies the maximum number of system requests made by WorkManager when using JobScheduler or AlarmManager.

Configuration.Builder setMinimumLoggingLevel(int loggingLevel)

Specifies the minimum logging level, corresponding to the constants found in Log.

Configuration.Builder setTaskExecutor(Executor taskExecutor)

Specifies a Executor which will be used by WorkManager for all its internal book-keeping.

Configuration.Builder setWorkerFactory(WorkerFactory workerFactory)

Specifies a custom WorkerFactory for WorkManager.

Inherited methods

Public constructors

Configuration.Builder

public Configuration.Builder ()

Public methods

build

public Configuration build ()

Builds a Configuration object.

Returns
Configuration A Configuration object with this Configuration.Builder's parameters.

setExecutor

public Configuration.Builder setExecutor (Executor executor)

Specifies a custom Executor for WorkManager.

Parameters
executor Executor: An Executor for running Workers

Returns
Configuration.Builder This Configuration.Builder instance

setJobSchedulerJobIdRange

public Configuration.Builder setJobSchedulerJobIdRange (int minJobSchedulerId, 
                int maxJobSchedulerId)

Specifies the range of JobInfo IDs that can be used by WorkManager. WorkManager needs a range of at least 1000 IDs.

JobScheduler uses integers as identifiers for jobs, and WorkManager delegates to JobScheduler on certain API levels. In order to not clash job codes used in the rest of your app, you can use this method to tell WorkManager the valid range of job IDs that it can use.

The default values are 0 and Integer#MAX_VALUE.

Parameters
minJobSchedulerId int: The first valid JobInfo ID (inclusive).

maxJobSchedulerId int: The last valid JobInfo ID (inclusive).

Returns
Configuration.Builder This Configuration.Builder instance

Throws
IllegalArgumentException when the size of the range is less than 1000

setMaxSchedulerLimit

public Configuration.Builder setMaxSchedulerLimit (int maxSchedulerLimit)

Specifies the maximum number of system requests made by WorkManager when using JobScheduler or AlarmManager.

By default, WorkManager might schedule a large number of alarms or JobScheduler jobs. If your app uses JobScheduler or AlarmManager directly, this might exhaust the OS-enforced limit on the number of jobs or alarms an app is allowed to schedule. To help manage this situation, you can use this method to reduce the number of underlying jobs and alarms that WorkManager might schedule.

When the application exceeds this limit, WorkManager maintains an internal queue of WorkRequests, and schedules them when slots become free.

WorkManager requires a minimum of Configuration.MIN_SCHEDULER_LIMIT slots; this is also the default value. The total number of slots also cannot exceed 50.

Parameters
maxSchedulerLimit int: The total number of jobs which can be enqueued by WorkManager when using JobScheduler.

Returns
Configuration.Builder This Configuration.Builder instance

Throws
IllegalArgumentException if maxSchedulerLimit is less than Configuration.MIN_SCHEDULER_LIMIT

setMinimumLoggingLevel

public Configuration.Builder setMinimumLoggingLevel (int loggingLevel)

Specifies the minimum logging level, corresponding to the constants found in Log. For example, specifying Log.VERBOSE will log everything, whereas specifying Log.ERROR will only log errors and assertions.The default value is Log.INFO.

Parameters
loggingLevel int: The minimum logging level, corresponding to the constants found in Log

Returns
Configuration.Builder This Configuration.Builder instance

setTaskExecutor

public Configuration.Builder setTaskExecutor (Executor taskExecutor)

Specifies a Executor which will be used by WorkManager for all its internal book-keeping. For best performance this Executor should be bounded. For more information look at RoomDatabase.Builder.setQueryExecutor(Executor).

Parameters
taskExecutor Executor: The Executor which will be used by WorkManager for all its internal book-keeping

Returns
Configuration.Builder This Configuration.Builder instance

setWorkerFactory

public Configuration.Builder setWorkerFactory (WorkerFactory workerFactory)

Specifies a custom WorkerFactory for WorkManager.

Parameters
workerFactory WorkerFactory: A WorkerFactory for creating ListenableWorkers

Returns
Configuration.Builder This Configuration.Builder instance