Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

Builder

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

A Builder for Configurations.

Summary

Public constructors

A Builder for Configurations.

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

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

Configuration.Builder
setExecutor(@NonNull executor: Executor)

Specifies a custom Executor for WorkManager.

Configuration.Builder
setMinimumLoggingLevel(loggingLevel: Int)

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

Configuration.Builder
setWorkerFactory(@NonNull workerFactory: WorkerFactory)

Specifies a custom WorkerFactory for 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

Builds a Configuration object.

Public constructors

<init>

Builder()

A Builder for Configurations.

Public methods

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

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

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

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

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

build

@NonNull fun build(): Configuration

Builds a Configuration object.

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