Builder
abstract class Builder<B : WorkRequest.Builder<*, *>!, W : WorkRequest!>
kotlin.Any | |
↳ | androidx.work.WorkRequest.Builder |
A builder for WorkRequest
s. There are two concrete implementations of this class: OneTimeWorkRequest.Builder
and PeriodicWorkRequest.Builder
.
Summary
Public methods | |
---|---|
B |
Adds a tag for the work. |
W |
build() Builds a |
B |
keepResultsForAtLeast(duration: Long, @NonNull timeUnit: TimeUnit) Specifies that the results of this work should be kept for at least the specified amount of time. |
B |
keepResultsForAtLeast(@NonNull duration: Duration) Specifies that the results of this work should be kept for at least the specified amount of time. |
B |
setBackoffCriteria(@NonNull backoffPolicy: BackoffPolicy, backoffDelay: Long, @NonNull timeUnit: TimeUnit) Sets the backoff policy and backoff delay for the work. |
B |
setBackoffCriteria(@NonNull backoffPolicy: BackoffPolicy, @NonNull duration: Duration) Sets the backoff policy and backoff delay for the work. |
B |
setConstraints(@NonNull constraints: Constraints) Adds constraints to the |
open B |
setExpedited(@NonNull policy: OutOfQuotaPolicy) Marks the |
open B |
setInitialDelay(duration: Long, @NonNull timeUnit: TimeUnit) Sets an initial delay for the |
open B |
setInitialDelay(@NonNull duration: Duration) Sets an initial delay for the |
B |
setInputData(@NonNull inputData: Data) Adds input |
Public methods
addTag
@NonNull fun addTag(@NonNull tag: String): B
Adds a tag for the work. You can query and cancel work by tags. Tags are particularly useful for modules or libraries to find and operate on their own work.
Parameters | |
---|---|
tag |
String: A tag for identifying the work in queries. |
Return | |
---|---|
B |
The current Builder |
build
@NonNull fun build(): W
Builds a WorkRequest
based on this Builder
.
Return | |
---|---|
W |
A WorkRequest based on this Builder |
keepResultsForAtLeast
@NonNull fun keepResultsForAtLeast(
duration: Long,
@NonNull timeUnit: TimeUnit
): B
Specifies that the results of this work should be kept for at least the specified amount of time. After this time has elapsed, the results may be pruned at the discretion of WorkManager when there are no pending dependent jobs.
When the results of a work are pruned, it becomes impossible to query for its WorkInfo
.
Specifying a long duration here may adversely affect performance in terms of app storage and database query time.
Parameters | |
---|---|
duration |
Long: The minimum duration of time (in timeUnit units) to keep the results of this work |
timeUnit |
TimeUnit: The unit of time for duration |
Return | |
---|---|
B |
The current Builder |
keepResultsForAtLeast
@RequiresApi(26) @NonNull fun keepResultsForAtLeast(@NonNull duration: Duration): B
Specifies that the results of this work should be kept for at least the specified amount of time. After this time has elapsed, the results
may
be pruned at the discretion of WorkManager when this WorkRequest has reached a finished state (seeWorkInfo.State#isFinished()
) and there are no pending dependent jobs.
When the results of a work are pruned, it becomes impossible to query for its WorkInfo
.
Specifying a long duration here may adversely affect performance in terms of app storage and database query time.
Parameters | |
---|---|
duration |
Duration: The minimum duration of time to keep the results of this work |
Return | |
---|---|
B |
The current Builder |
setBackoffCriteria
@NonNull fun setBackoffCriteria(
@NonNull