Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

Builder

class Builder
kotlin.Any
   ↳ androidx.work.Configuration.Builder

A Builder for Configurations.

Summary

Public constructors

Creates a new Configuration.Builder.

Public methods

Configuration

Builds a Configuration object.

Configuration.Builder
setExecutor(@NonNull executor: Executor)

Specifies a custom Executor for WorkManager.

Configuration.Builder
setInputMergerFactory(@NonNull inputMergerFactory: InputMergerFactory)

Specifies a custom InputMergerFactory for WorkManager.

Configuration.Builder
setJobSchedulerJobIdRange(minJobSchedulerId: Int, maxJobSchedulerId: Int)

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

Configuration.Builder
setMaxSchedulerLimit(maxSchedulerLimit: Int)

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

Configuration.Builder
setMinimumLoggingLevel(loggingLevel: Int)

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

Configuration.Builder
setTaskExecutor(@NonNull taskExecutor: Executor)

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

Configuration.Builder
setWorkerFactory(@NonNull workerFactory: WorkerFactory)

Specifies a custom WorkerFactory for WorkManager.

Public constructors

<init>

Builder()

Creates a new Configuration.Builder.

Public methods

build

@NonNull fun build(): Configuration

Builds a Configuration object.

Return
Configuration: A Configuration object with this Builder's parameters.

setExecutor

@NonNull fun setExecutor(@NonNull executor: Executor): Configuration.Builder

Specifies a custom Executor for WorkManager.

Parameters
executor Executor: An Executor for running Workers
Return
Configuration.Builder: This Builder instance

setInputMergerFactory

@NonNull fun setInputMergerFactory(@NonNull inputMergerFactory: InputMergerFactory): Configuration.Builder

Specifies a custom InputMergerFactory for WorkManager.

Parameters
inputMergerFactory InputMergerFactory: A InputMergerFactory for creating InputMergers
Return
Configuration.Builder: This Builder instance

setJobSchedulerJobIdRange

@NonNull fun setJobSchedulerJobIdRange(minJobSchedulerId: Int, maxJobSchedulerId: Int): Configuration.Builder

Specifies the range of android.app.job.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 android.app.job.JobInfo ID (inclusive).
maxJobSchedulerId Int: The last valid android.app.job.JobInfo ID (inclusive).
Return
Configuration.Builder: This Builder instance
Exceptions
IllegalArgumentException when the size of the range is less than 1000

setMaxSchedulerLimit

@NonNull fun setMaxSchedulerLimit(maxSchedulerLimit: Int): Configuration.Builder

Specifies the maximum number of system requests made by WorkManager when using android.app.job.JobScheduler or android.app.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 android.app.job.JobScheduler.
Return
Configuration.Builder: This Builder instance
Exceptions
IllegalArgumentException if maxSchedulerLimit is less than Configuration#MIN_SCHEDULER_LIMIT

setMinimumLoggingLevel

@NonNull fun setMinimumLoggingLevel(loggingLevel: Int): Configuration.Builder

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

Parameters
loggingLevel Int: The minimum logging level, corresponding to the constants found in android.util.Log
Return
Configuration.Builder: This Builder instance

setTaskExecutor

@NonNull fun setTaskExecutor(@NonNull taskExecutor: Executor): Configuration.Builder

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 androidx.room.RoomDatabase.Builder#setQueryExecutor(Executor).

Parameters
taskExecutor Executor: The Executor which will be used by WorkManager for all its internal book-keeping
Return
Configuration.Builder: This Builder instance

setWorkerFactory

@NonNull fun setWorkerFactory(@NonNull workerFactory: WorkerFactory): Configuration.Builder

Specifies a custom WorkerFactory for WorkManager.

Parameters
workerFactory WorkerFactory: A WorkerFactory for creating ListenableWorkers
Return
Configuration.Builder: This Builder instance