Configuration.Builder
class Configuration.Builder
A Builder for Configurations.
Summary
Public constructors |
|---|
Builder()Creates a new |
Public functions |
|
|---|---|
Configuration |
build()Builds a |
Configuration.Builder |
Sets a |
Configuration.Builder |
setContentUriTriggerWorkersLimit(contentUriTriggerWorkersLimit: Int)Specifies the maximum number of Workers with |
Configuration.Builder |
setDefaultProcessName(processName: String)Designates the primary process that |
Configuration.Builder |
Set a |
Configuration.Builder |
setExecutor(executor: Executor)Specifies a custom |
Configuration.Builder |
Specifies whether the in-process opportunistic greedy scheduler should be enabled. |
Configuration.Builder |
setInitializationExceptionHandler(Specifies a |
Configuration.Builder |
setInputMergerFactory(inputMergerFactory: InputMergerFactory)Specifies a custom |
Configuration.Builder |
setJobSchedulerJobIdRange(minJobSchedulerId: Int, maxJobSchedulerId: Int)Specifies the range of |
Configuration.Builder |
@ExperimentalConfigurationApiRegulates whether WorkManager should automatically set |
Configuration.Builder |
setMaxSchedulerLimit(maxSchedulerLimit: Int)Specifies the maximum number of system requests made by |
Configuration.Builder |
setMinimumLoggingLevel(loggingLevel: Int)Specifies the minimum logging level, corresponding to the constants found in |
Configuration.Builder |
setRemoteSessionTimeoutMillis(Set how long in milliseconds that a |
Configuration.Builder |
setRunnableScheduler(runnableScheduler: RunnableScheduler)Specifies the |
Configuration.Builder |
Set a |
Configuration.Builder |
setSchedulingExceptionHandler(Specifies a |
Configuration.Builder |
setTaskExecutor(taskExecutor: Executor)Specifies a |
Configuration.Builder |
setWorkerCoroutineContext(context: CoroutineContext)Specifies a custom |
Configuration.Builder |
setWorkerExecutionExceptionHandler(Specifies a |
Configuration.Builder |
setWorkerFactory(workerFactory: WorkerFactory)Specifies a custom |
Configuration.Builder |
setWorkerInitializationExceptionHandler(Specifies a |
Public constructors
Public functions
build
fun build(): Configuration
Builds a Configuration object.
| Returns | |
|---|---|
Configuration |
A |
setClock
fun setClock(clock: Clock): Configuration.Builder
Sets a Clock for WorkManager to calculate schedules and perform book-keeping.
This should only be overridden for testing. It must return the same value as System.currentTimeMillis in production code.
| Returns | |
|---|---|
Configuration.Builder |
This |
setContentUriTriggerWorkersLimit
fun setContentUriTriggerWorkersLimit(contentUriTriggerWorkersLimit: Int): Configuration.Builder
Specifies the maximum number of Workers with Constraints.contentUriTriggers that could be enqueued simultaneously.
Unlike the other workers Workers with Constraints.contentUriTriggers must immediately occupy slots in JobScheduler to avoid missing updates, thus they are separated in its own category.
setDefaultProcessName
fun setDefaultProcessName(processName: String): Configuration.Builder
Designates the primary process that WorkManager should schedule work in.
| Returns | |
|---|---|
Configuration.Builder |
This |
setExecutionEventListener
@ExperimentalEventsApi
fun setExecutionEventListener(listener: ExecutionEventListener): Configuration.Builder
Set a ExecutionEventListener to run whenever work execution events occur for any worker.
These callbacks will be invoked on a thread bound to Configuration.taskExecutor.
| Parameters | |
|---|---|
listener: ExecutionEventListener |
|
| Returns | |
|---|---|
Configuration.Builder |
This |
setExecutor
fun setExecutor(executor: Executor): Configuration.Builder
Specifies a custom Executor to run Worker.doWork.
If setWorkerCoroutineContext wasn't called then the executor will be used as CoroutineDispatcher to run CoroutineWorker as well.
| Returns | |
|---|---|
Configuration.Builder |
This |
setGreedySchedulerEnabled
@ExperimentalConfigurationApi
fun setGreedySchedulerEnabled(enabled: Boolean): Configuration.Builder
Specifies whether the in-process opportunistic greedy scheduler should be enabled.
This is enabled by default and should only be disabled for experimental purposes.
| Parameters | |
|---|---|
enabled: Boolean |
whether to enable the greedy scheduler |
| Returns | |
|---|---|
Configuration.Builder |
This |
setInitializationExceptionHandler
fun setInitializationExceptionHandler(
exceptionHandler: Consumer<Throwable>
): Configuration.Builder
Specifies a Consumer<Throwable> that can be used to intercept exceptions caused when trying to initialize {@link WorkManager}, that usually happens when WorkManager cannot access its internal datastore.
This exception handler will be invoked on a thread bound to Configuration.taskExecutor.
| Returns | |
|---|---|
Configuration.Builder |
This |
setInputMergerFactory
fun setInputMergerFactory(inputMergerFactory: InputMergerFactory): Configuration.Builder
Specifies a custom InputMergerFactory for WorkManager.
| Parameters | |
|---|---|
inputMergerFactory: InputMergerFactory |
A |
| Returns | |
|---|---|
Configuration.Builder |
This |
setJobSchedulerJobIdRange
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 |
maxJobSchedulerId: Int |
The last valid |
| Returns | |
|---|---|
Configuration.Builder |
This |
| Throws | |
|---|---|
IllegalArgumentException |
when the size of the range is less than 1000 |
setMarkingJobsAsImportantWhileForeground
@ExperimentalConfigurationApi
fun setMarkingJobsAsImportantWhileForeground(markAsImportant: Boolean): Configuration.Builder
Regulates whether WorkManager should automatically set android.app.job.JobInfo.Builder.setImportantWhileForeground for workers that are eligible to run immediately.
It will have effects only on API levels >= 23.
| Parameters | |
|---|---|
markAsImportant: Boolean |
whether to mark jobs as important |
| Returns | |
|---|---|
Configuration.Builder |
This |
setMaxSchedulerLimit
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 |
| Returns | |
|---|---|
Configuration.Builder |
This |
| Throws | |
|---|---|
IllegalArgumentException |
if |
setMinimumLoggingLevel
fun setMinimumLoggingLevel(loggingLevel: Int): Configuration.Builder
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.
| Returns | |
|---|---|
Configuration.Builder |
This |
setRemoteSessionTimeoutMillis
fun setRemoteSessionTimeoutMillis(
timeoutMillis: @IntRange(from = 0, to = 1200000) Long
): Configuration.Builder
Set how long in milliseconds that a androidx.work.multiprocess.RemoteWorkManager binding to the designated process stays active before timing out and unbinding.
The default timeout is androidx.work.multiprocess.RemoteWorkManager.DEFAULT_SESSION_TIMEOUT_MILLIS and can be configured up to androidx.work.multiprocess.RemoteWorkManager.MAX_SESSION_TIMEOUT_MILLIS. A timeout of 0 will unbind immediately after each call.
| Parameters | |
|---|---|
timeoutMillis: @IntRange(from = 0, to = 1200000) Long |
Timeout in milliseconds before the session unbinds |
| Returns | |
|---|---|
Configuration.Builder |
This |
setRunnableScheduler
fun setRunnableScheduler(runnableScheduler: RunnableScheduler): Configuration.Builder
Specifies the RunnableScheduler to be used by WorkManager.
This is used by the in-process scheduler to keep track of timed work.
| Parameters | |
|---|---|
runnableScheduler: RunnableScheduler |
The |
| Returns | |
|---|---|
Configuration.Builder |
This |
setScheduleEventListener
@ExperimentalEventsApi
fun setScheduleEventListener(listener: ScheduleEventListener): Configuration.Builder
Set a ScheduleEventListener to run whenever work scheduling events occur for any worker.
These callbacks will be invoked on a thread bound to Configuration.taskExecutor.
| Parameters | |
|---|---|
listener: ScheduleEventListener |
|
| Returns | |
|---|---|
Configuration.Builder |
This |
setSchedulingExceptionHandler
fun setSchedulingExceptionHandler(
schedulingExceptionHandler: Consumer<Throwable>
): Configuration.Builder
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 Configuration.taskExecutor.
| Returns | |
|---|---|
Configuration.Builder |
This |
setTaskExecutor
fun setTaskExecutor(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.
| Parameters | |
|---|---|
taskExecutor: Executor |
The |
| Returns | |
|---|---|
Configuration.Builder |
This |
setWorkerCoroutineContext
fun setWorkerCoroutineContext(context: CoroutineContext): Configuration.Builder
Specifies a custom CoroutineContext to run CoroutineWorker.doWork. WorkManager will use its own Job with the provided CoroutineContext.
If setExecutor wasn't called then context will be used as Executor to run Worker as well.
| Parameters | |
|---|---|
context: CoroutineContext |
A |
| Returns | |
|---|---|
Configuration.Builder |
This |
setWorkerExecutionExceptionHandler
fun setWorkerExecutionExceptionHandler(
workerExceptionHandler: Consumer<WorkerExceptionInfo>
): Configuration.Builder
Specifies a WorkerExceptionHandler that can be used to intercept exceptions caused when trying to execute ListenableWorkers.
This exception handler will be invoked on a thread bound to Configuration.taskExecutor.
| Parameters | |
|---|---|
workerExceptionHandler: Consumer<WorkerExceptionInfo> |
an instance to handle exceptions |
| Returns | |
|---|---|
Configuration.Builder |
This |
setWorkerFactory
fun setWorkerFactory(workerFactory: WorkerFactory): Configuration.Builder
Specifies a custom WorkerFactory for WorkManager.
| Parameters | |
|---|---|
workerFactory: WorkerFactory |
A |
| Returns | |
|---|---|
Configuration.Builder |
This |
setWorkerInitializationExceptionHandler
fun setWorkerInitializationExceptionHandler(
workerExceptionHandler: Consumer<WorkerExceptionInfo>
): Configuration.Builder
Specifies a WorkerExceptionHandler that can be used to intercept exceptions caused when trying to initialize ListenableWorkers.
This exception handler will be invoked on a thread bound to Configuration.taskExecutor.
| Parameters | |
|---|---|
workerExceptionHandler: Consumer<WorkerExceptionInfo> |
an instance to handle exceptions |
| Returns | |
|---|---|
Configuration.Builder |
This |