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

androidx.work

Classes

ArrayCreatingInputMerger

An InputMerger that attempts to merge the inputs, creating arrays when necessary.

Configuration

The Configuration object used to customize WorkManager upon initialization.

Constraints

A specification of the requirements that need to be met before a WorkRequest can run.

CoroutineWorker

A ListenableWorker implementation that provides interop with Kotlin Coroutines.

Data

A persistable set of key/value pairs which are used as inputs and outputs for ListenableWorkers.

DelegatingWorkerFactory

A WorkerFactory which delegates to other factories.

ForegroundInfo

The information required when a ListenableWorker runs in the context of a foreground service.

InputMerger

An abstract class that allows the user to define how to merge a list of inputs to a ListenableWorker.

InputMergerFactory

A factory object that creates InputMerger instances.

ListenableWorker

A class that can perform work asynchronously in WorkManager.

OneTimeWorkRequest

A WorkRequest for non-repeating work.

OverwritingInputMerger

An InputMerger that attempts to add all keys from all inputs to the output.

PeriodicWorkRequest

A WorkRequest for repeating work.

RxWorker

RxJava2 interoperability Worker implementation.

WorkContinuation

A class that allows you to chain together OneTimeWorkRequests.

Worker

A class that performs work synchronously on a background thread provided by WorkManager.

WorkerFactory

A factory object that creates ListenableWorker instances.

WorkerParameters

Setup parameters for a ListenableWorker.

WorkInfo

Information about a particular WorkRequest containing the id of the WorkRequest, its current State, output, tags, and run attempt count.

WorkManager

WorkManager is a library used to enqueue deferrable work that is guaranteed to execute sometime after its Constraints are met.

WorkRequest

The base class for specifying parameters for work that should be enqueued in WorkManager.

Enums

BackoffPolicy

An enumeration of backoff policies when retrying work.

DirectExecutor

A simple Executor.

ExistingPeriodicWorkPolicy

An enumeration of the conflict resolution policies available to unique PeriodicWorkRequests in case of a collision.

ExistingWorkPolicy

An enumeration of the conflict resolution policies available to unique OneTimeWorkRequests in case of a collision.

NetworkType

An enumeration of various network types that can be used as Constraints for work.

Top-level functions summary

OneTimeWorkRequest.Builder

Creates a OneTimeWorkRequest with the given ListenableWorker.

PeriodicWorkRequest.Builder
PeriodicWorkRequestBuilder(repeatInterval: Long, repeatIntervalTimeUnit: TimeUnit)

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

PeriodicWorkRequest.Builder

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

PeriodicWorkRequest.Builder
PeriodicWorkRequestBuilder(repeatInterval: Long, repeatIntervalTimeUnit: TimeUnit, flexTimeInterval: Long, flexTimeIntervalUnit: TimeUnit)

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

PeriodicWorkRequest.Builder
PeriodicWorkRequestBuilder(repeatInterval: Duration, flexTimeInterval: Duration)

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

Data
workDataOf(vararg pairs: Pair<String, Any?>)

Converts a list of pairs to a Data object.

Extension functions summary

For com.google.common.util.concurrent.ListenableFuture
suspend R

Awaits for the completion of the ListenableFuture without blocking a thread.

For Operation
suspend Operation.State.SUCCESS!

Awaits an Operation without blocking a thread.

For Data
Boolean

Returns true if the instance of Data has a value corresponding to the given key with an expected type T.

For Builder
OneTimeWorkRequest.Builder

Sets an InputMerger on the OneTimeWorkRequest.Builder.

Top-level functions

OneTimeWorkRequestBuilder

inline fun <reified W : ListenableWorker> OneTimeWorkRequestBuilder(): OneTimeWorkRequest.Builder

Creates a OneTimeWorkRequest with the given ListenableWorker.

PeriodicWorkRequestBuilder

inline fun <reified W : ListenableWorker> PeriodicWorkRequestBuilder(repeatInterval: Long, repeatIntervalTimeUnit: TimeUnit): PeriodicWorkRequest.Builder

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

Parameters
repeatInterval @see androidx.work.PeriodicWorkRequest.Builder
repeatIntervalTimeUnit @see androidx.work.PeriodicWorkRequest.Builder

PeriodicWorkRequestBuilder

inline fun <reified W : ListenableWorker> PeriodicWorkRequestBuilder(repeatInterval: Duration): PeriodicWorkRequest.Builder

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

Parameters
repeatInterval @see androidx.work.PeriodicWorkRequest.Builder

PeriodicWorkRequestBuilder

inline fun <reified W : ListenableWorker> PeriodicWorkRequestBuilder(repeatInterval: Long, repeatIntervalTimeUnit: TimeUnit, flexTimeInterval: Long, flexTimeIntervalUnit: TimeUnit): PeriodicWorkRequest.Builder

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

Parameters
repeatInterval @see androidx.work.PeriodicWorkRequest.Builder
repeatIntervalTimeUnit @see androidx.work.PeriodicWorkRequest.Builder
flexInterval @see androidx.work.PeriodicWorkRequest.Builder
flexIntervalTimeUnit @see androidx.work.PeriodicWorkRequest.Builder

PeriodicWorkRequestBuilder

inline fun <reified W : ListenableWorker> PeriodicWorkRequestBuilder(repeatInterval: Duration, flexTimeInterval: Duration): PeriodicWorkRequest.Builder

Creates a PeriodicWorkRequest.Builder with a given ListenableWorker.

Parameters
repeatInterval @see androidx.work.PeriodicWorkRequest.Builder
flexInterval @see androidx.work.PeriodicWorkRequest.Builder

workDataOf

inline fun workDataOf(vararg pairs: Pair<String, Any?>): Data

Converts a list of pairs to a Data object.

If multiple pairs have the same key, the resulting map will contain the value from the last of those pairs.

Entries of the map are iterated in the order they were specified.

Extension functions

await

inline suspend fun <R> ListenableFuture<R>.await(): R

Awaits for the completion of the ListenableFuture without blocking a thread.

Return
R The result from the ListenableFuture

await

inline suspend fun Operation.await(): Operation.State.SUCCESS!

Awaits an Operation without blocking a thread.

hasKeyWithValueOfType

inline fun <reified T : Any> Data.hasKeyWithValueOfType(key: String): Boolean

Returns true if the instance of Data has a value corresponding to the given key with an expected type T.

setInputMerger

inline fun OneTimeWorkRequest.Builder.setInputMerger(@NonNull inputMerger: KClass<out InputMerger>): OneTimeWorkRequest.Builder

Sets an InputMerger on the OneTimeWorkRequest.Builder.