Stay organized with collections Save and categorize content based on your preferences.

Configuration.Builder

public final class Configuration.Builder


A Builder for Configurations.

Summary

Public constructors

Creates a new Configuration.Builder.

Public methods

@NonNull Configuration

Builds a Configuration object.

@NonNull Configuration.Builder

Designates the primary process that WorkManager should schedule work in.

@NonNull Configuration.Builder

Specifies a custom Executor for WorkManager.

@NonNull Configuration.Builder

Specifies a Consumer<Throwable> that can be used to intercept exceptions caused when trying to initialize WorkManager, that usually happens when WorkManager cannot access its internal datastore.

@NonNull Configuration.Builder

Specifies a custom InputMergerFactory for WorkManager.

@NonNull Configuration.Builder
setJobSchedulerJobIdRange(int minJobSchedulerId, int maxJobSchedulerId)

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

@NonNull Configuration.Builder
setMaxSchedulerLimit(int maxSchedulerLimit)

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

@NonNull Configuration.Builder
setMinimumLoggingLevel(int loggingLevel)

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

@NonNull Configuration.Builder

Specifies the RunnableScheduler to be used by WorkManager.

@NonNull Configuration.Builder
setSchedulingExceptionHandler(
    @NonNull Consumer<Throwable> schedulingExceptionHandler
)

Specifies a Consumer<Throwable> that can be used to intercept exceptions caused when trying to schedule WorkRequests.

@NonNull Configuration.Builder

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

@NonNull Configuration.Builder

Specifies a custom WorkerFactory for WorkManager.

Public constructors

Builder

public Builder()

Creates a new Configuration.Builder.

Public methods

build

public @NonNull Configuration build()

Builds a Configuration object.

Returns
@NonNull Configuration

A Configuration object with this Builder's parameters.

setDefaultProcessName

public @NonNull Configuration.Builder setDefaultProcessName(@NonNull String processName)

Designates the primary process that WorkManager should schedule work in.

Parameters
@NonNull String processName

The String process name.

Returns
@NonNull Configuration.Builder

This Builder instance

setExecutor

public @NonNull Configuration.Builder setExecutor(@NonNull Executor executor)

Specifies a custom Executor for WorkManager.

Parameters
@NonNull Executor executor

An Executor for running Workers

Returns
@NonNull Configuration.Builder

This Builder instance

setInitializationExceptionHandler

public @NonNull Configuration.Builder setInitializationExceptionHandler(
    @NonNull Consumer<Throwable> exceptionHandler
)

Specifies a Consumer<Throwable> that can be used to intercept exceptions caused when trying to initialize WorkManager, that usually happens when WorkManager cannot access its internal datastore.

This exception handler will be invoked on a thread bound to getTaskExecutor.

Parameters
@NonNull Consumer<Throwable> exceptionHandler

an instance to handle exceptions

Returns
@NonNull Configuration.Builder

This Builder instance

setInputMergerFactory

public @NonNull Configuration.Builder setInputMergerFactory(@NonNull InputMergerFactory inputMergerFactory)

Specifies a custom InputMergerFactory for WorkManager.

Parameters
@NonNull InputMergerFactory inputMergerFactory

A InputMergerFactory for creating InputMergers

Returns
@NonNull Configuration.Builder

This Builder instance

setJobSchedulerJobIdRange

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

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
int minJobSchedulerId

The first valid android.app.job.JobInfo ID (inclusive).

int maxJobSchedulerId

The last valid android.app.job.JobInfo ID (inclusive).

Returns
@NonNull Configuration.Builder

This Builder instance

Throws
java.lang.IllegalArgumentException java.lang.IllegalArgumentException

when the size of the range is less than 1000

setMaxSchedulerLimit

public @NonNull Configuration.Builder setMaxSchedulerLimit(int maxSchedulerLimit)

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 MIN_SCHEDULER_LIMIT slots; this is also the default value. The total number of slots also cannot exceed 50.

Parameters
int maxSchedulerLimit

The total number of jobs which can be enqueued by WorkManager when using android.app.job.JobScheduler.

Returns
@NonNull Configuration.Builder

This Builder instance

Throws
java.lang.IllegalArgumentException java.lang.IllegalArgumentException

if maxSchedulerLimit is less than MIN_SCHEDULER_LIMIT

setMinimumLoggingLevel

public @NonNull Configuration.Builder setMinimumLoggingLevel(int loggingLevel)

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

Parameters
int loggingLevel

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

Returns
@NonNull Configuration.Builder

This Builder instance

setRunnableScheduler

public @NonNull Configuration.Builder setRunnableScheduler(@NonNull RunnableScheduler runnableScheduler)

Specifies the RunnableScheduler to be used by WorkManager. This is used by the in-process scheduler to keep track of timed work.

Parameters
@NonNull RunnableScheduler runnableScheduler

The RunnableScheduler to be used

Returns
@NonNull Configuration.Builder

This Builder instance

setSchedulingExceptionHandler

public @NonNull Configuration.Builder setSchedulingExceptionHandler(
    @NonNull Consumer<Throwable> schedulingExceptionHandler
)

Specifies a Consumer<Throwable> that can be used to intercept exceptions caused when trying to schedule WorkRequests. It allows the application to handle a Throwable throwable typically caused when trying to schedule WorkRequests.

This exception handler will be invoked on a thread bound to getTaskExecutor.

Parameters
@NonNull Consumer<Throwable> schedulingExceptionHandler

an instance to handle exceptions

Returns
@NonNull Configuration.Builder

This Builder instance

setTaskExecutor

public @NonNull Configuration.Builder setTaskExecutor(@NonNull 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 setQueryExecutor.

Parameters
@NonNull Executor taskExecutor

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

Returns
@NonNull Configuration.Builder

This Builder instance

setWorkerFactory

public @NonNull Configuration.Builder setWorkerFactory(@NonNull WorkerFactory workerFactory)

Specifies a custom WorkerFactory for WorkManager.

Parameters
@NonNull WorkerFactory workerFactory

A WorkerFactory for creating ListenableWorkers

Returns
@NonNull Configuration.Builder

This Builder instance