RemoteWorkManager
public abstract class RemoteWorkManager
A subset of androidx.work.WorkManager
APIs that are available for apps that use multiple processes.
Summary
Public methods |
|
---|---|
abstract @NonNull RemoteWorkContinuation |
beginUniqueWork( This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. |
final @NonNull RemoteWorkContinuation |
beginUniqueWork( This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. |
abstract @NonNull RemoteWorkContinuation |
beginWith(@NonNull List<OneTimeWorkRequest> work) Begins a chain with one or more |
final @NonNull RemoteWorkContinuation |
beginWith(@NonNull OneTimeWorkRequest work) Begins a chain with one or more |
abstract @NonNull ListenableFuture<Void> |
Cancels all unfinished work. |
abstract @NonNull ListenableFuture<Void> |
cancelAllWorkByTag(@NonNull String tag) Cancels all unfinished work with the given tag. |
abstract @NonNull ListenableFuture<Void> |
cancelUniqueWork(@NonNull String uniqueWorkName) Cancels all unfinished work in the work chain with the given name. |
abstract @NonNull ListenableFuture<Void> |
cancelWorkById(@NonNull UUID id) Cancels work with the given id if it isn't finished. |
abstract @NonNull ListenableFuture<Void> |
enqueue(@NonNull WorkRequest request) Enqueues one item for background processing. |
abstract @NonNull ListenableFuture<Void> |
enqueue(@NonNull List<WorkRequest> requests) Enqueues one or more items for background processing. |
abstract @NonNull ListenableFuture<Void> |
enqueueUniquePeriodicWork( This method allows you to enqueue a uniquely-named |
abstract @NonNull ListenableFuture<Void> |
enqueueUniqueWork( This method allows you to enqueue |
final @NonNull ListenableFuture<Void> |
enqueueUniqueWork( This method allows you to enqueue |
static @NonNull RemoteWorkManager |
getInstance(@NonNull Context context) Gets the instance of |
abstract @NonNull ListenableFuture<List<WorkInfo>> |
getWorkInfos(@NonNull WorkQuery workQuery) Gets the |
Public methods
beginUniqueWork
public abstract @NonNull RemoteWorkContinuation beginUniqueWork(
@NonNull String uniqueWorkName,
@NonNull ExistingWorkPolicy existingWorkPolicy,
@NonNull List<OneTimeWorkRequest> work
)
This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.
The uniqueWorkName
uniquely identifies this set of work.
If this method determines that new work should be enqueued and run, all records of previous work with uniqueWorkName
will be pruned. If this method determines that new work should NOT be run, then the entire chain will be considered a no-op.
If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run. This is particularly important if you are using APPEND
as your ExistingWorkPolicy
.
Parameters | |
---|---|
@NonNull String uniqueWorkName |
A unique name which for this chain of work |
@NonNull ExistingWorkPolicy existingWorkPolicy |
An |
@NonNull List<OneTimeWorkRequest> work |
One or more |
Returns | |
---|---|
@NonNull RemoteWorkContinuation |
A |
beginUniqueWork
public final @NonNull RemoteWorkContinuation beginUniqueWork(
@NonNull String uniqueWorkName,
@NonNull ExistingWorkPolicy existingWorkPolicy,
@NonNull OneTimeWorkRequest work
)
This method allows you to begin unique chains of work for situations where you only want one chain with a given name to be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.
The uniqueWorkName
uniquely identifies this set of work.
If this method determines that new work should be enqueued and run, all records of previous work with uniqueWorkName
will be pruned. If this method determines that new work should NOT be run, then the entire chain will be considered a no-op.
If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run. This is particularly important if you are using APPEND
as your ExistingWorkPolicy
.
Parameters | |
---|---|
@NonNull String uniqueWorkName |
A unique name which for this chain of work |
@NonNull ExistingWorkPolicy existingWorkPolicy |
|
@NonNull OneTimeWorkRequest work |
The |
Returns | |
---|---|
@NonNull RemoteWorkContinuation |
A |
beginWith
public abstract @NonNull RemoteWorkContinuation beginWith(@NonNull List<OneTimeWorkRequest> work)
Begins a chain with one or more OneTimeWorkRequest
s, which can be enqueued together in the future using enqueue
.
If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run.
Parameters | |
---|---|
@NonNull List<OneTimeWorkRequest> work |
One or more |
Returns | |
---|---|
@NonNull RemoteWorkContinuation |
A |
beginWith
public final @NonNull RemoteWorkContinuation beginWith(@NonNull OneTimeWorkRequest work)
Begins a chain with one or more OneTimeWorkRequest
s, which can be enqueued together in the future using enqueue
.
If any work in the chain fails or is cancelled, all of its dependent work inherits that state and will never run.
Parameters | |
---|---|
@NonNull OneTimeWorkRequest work |
One or more |
Returns | |
---|---|
@NonNull RemoteWorkContinuation |
A |
cancelAllWork
public abstract @NonNull ListenableFuture<Void> cancelAllWork()
Cancels all unfinished work. Use this method with extreme caution! By invoking it, you will potentially affect other modules or libraries in your codebase. It is strongly recommended that you use one of the other cancellation methods at your disposal.
Upon cancellation, onStopped
will be invoked for any affected workers.
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
cancelAllWorkByTag
public abstract @NonNull ListenableFuture<Void> cancelAllWorkByTag(@NonNull String tag)
Cancels all unfinished work with the given tag. Note that cancellation is a best-effort policy and work that is already executing may continue to run. Upon cancellation, onStopped
will be invoked for any affected workers.
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
An |
cancelUniqueWork
public abstract @NonNull ListenableFuture<Void> cancelUniqueWork(@NonNull String uniqueWorkName)
Cancels all unfinished work in the work chain with the given name. Note that cancellation is a best-effort policy and work that is already executing may continue to run. Upon cancellation, onStopped
will be invoked for any affected workers.
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
cancelWorkById
public abstract @NonNull ListenableFuture<Void> cancelWorkById(@NonNull UUID id)
Cancels work with the given id if it isn't finished. Note that cancellation is a best-effort policy and work that is already executing may continue to run. Upon cancellation, onStopped
will be invoked for any affected workers.
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
enqueue
public abstract @NonNull ListenableFuture<Void> enqueue(@NonNull WorkRequest request)
Enqueues one item for background processing.
Parameters | |
---|---|
@NonNull WorkRequest request |
The |
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
enqueue
public abstract @NonNull ListenableFuture<Void> enqueue(@NonNull List<WorkRequest> requests)
Enqueues one or more items for background processing.
Parameters | |
---|---|
@NonNull List<WorkRequest> requests |
One or more |
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
enqueueUniquePeriodicWork
public abstract @NonNull ListenableFuture<Void> enqueueUniquePeriodicWork(
@NonNull String uniqueWorkName,
@NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy,
@NonNull PeriodicWorkRequest periodicWork
)
This method allows you to enqueue a uniquely-named PeriodicWorkRequest
, where only one PeriodicWorkRequest of a particular name can be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.
The uniqueWorkName
uniquely identifies this PeriodicWorkRequest.
Parameters | |
---|---|
@NonNull String uniqueWorkName |
A unique name which for this operation |
@NonNull ExistingPeriodicWorkPolicy existingPeriodicWorkPolicy |
|
@NonNull PeriodicWorkRequest periodicWork |
A |
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
An |
enqueueUniqueWork
public abstract @NonNull ListenableFuture<Void> enqueueUniqueWork(
@NonNull String uniqueWorkName,
@NonNull ExistingWorkPolicy existingWorkPolicy,
@NonNull List<OneTimeWorkRequest> work
)
This method allows you to enqueue work
requests to a uniquely-named RemoteWorkContinuation
, where only one continuation of a particular name can be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.
The uniqueWorkName
uniquely identifies this RemoteWorkContinuation
.
Parameters | |
---|---|
@NonNull String uniqueWorkName |
A unique name which for this operation |
@NonNull ExistingWorkPolicy existingWorkPolicy |
|
@NonNull List<OneTimeWorkRequest> work |
|
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
enqueueUniqueWork
public final @NonNull ListenableFuture<Void> enqueueUniqueWork(
@NonNull String uniqueWorkName,
@NonNull ExistingWorkPolicy existingWorkPolicy,
@NonNull OneTimeWorkRequest work
)
This method allows you to enqueue work
requests to a uniquely-named RemoteWorkContinuation
, where only one continuation of a particular name can be active at a time. For example, you may only want one sync operation to be active. If there is one pending, you can choose to let it run or replace it with your new work.
The uniqueWorkName
uniquely identifies this RemoteWorkContinuation
.
Parameters | |
---|---|
@NonNull String uniqueWorkName |
A unique name which for this operation |
@NonNull ExistingWorkPolicy existingWorkPolicy |
An |
@NonNull OneTimeWorkRequest work |
The |
Returns | |
---|---|
@NonNull ListenableFuture<Void> |
A |
getInstance
public static @NonNull RemoteWorkManager getInstance(@NonNull Context context)
Gets the instance of RemoteWorkManager
which provides a subset of WorkManager
APIs that are safe to use for apps that use multiple processes.
Returns | |
---|---|
@NonNull RemoteWorkManager |
The instance of |
getWorkInfos
public abstract @NonNull ListenableFuture<List<WorkInfo>> getWorkInfos(@NonNull WorkQuery workQuery)
Gets the ListenableFuture
of the List
of WorkInfo
for all work referenced by the WorkQuery
specification.
Returns | |
---|---|
@NonNull ListenableFuture<List<WorkInfo>> |
A |