SynchronousWorkManager

public interface SynchronousWorkManager

androidx.work.SynchronousWorkManager


Blocking methods for WorkManager operations. These methods are expected to be called from a background thread.

Summary

Public methods

abstract void cancelAllWorkByTagSync(String tag)

Cancels all unfinished work with the given tag in a synchronous fashion.

abstract void cancelUniqueWorkSync(String uniqueWorkName)

Cancels all unfinished work in the work chain with the given name in a synchronous fashion.

abstract void cancelWorkByIdSync(UUID id)

Cancels work with the given id in a synchronous fashion if it isn't finished.

abstract void enqueueSync(WorkRequest... workRequest)

Enqueues one or more WorkRequest in a synchronous fashion.

abstract void enqueueSync(List<? extends WorkRequest> workRequest)

Enqueues the List of WorkRequest in a synchronous fashion.

abstract WorkStatus getStatusByIdSync(UUID id)

Gets the WorkStatus of a given work id in a synchronous fashion.

abstract List<WorkStatus> getStatusesByTagSync(String tag)

Gets the WorkStatus for all work with a given tag in a synchronous fashion.

abstract List<WorkStatus> getStatusesForUniqueWorkSync(String uniqueWorkName)

Gets the WorkStatus for all work for the chain of work with a given unique name in a synchronous fashion.

Public methods

cancelAllWorkByTagSync

void cancelAllWorkByTagSync (String tag)

Cancels all unfinished work with the given tag in a synchronous fashion. Note that cancellation is dependent on timing (for example, the work could have completed in a different thread just as you issue this call). Use getStatusByIdSync(UUID) to find out the actual state of the work after this call. This method is expected to be called from a background thread.

Parameters
tag String: The tag used to identify the work

cancelUniqueWorkSync

void cancelUniqueWorkSync (String uniqueWorkName)

Cancels all unfinished work in the work chain with the given name in a synchronous fashion. Note that cancellation is dependent on timing (for example, the work could have completed in a different thread just as you issue this call). Use getStatusByIdSync(UUID) to find out the actual state of the work after this call. This method is expected to be called from a background thread.

Parameters
uniqueWorkName String: The unique name used to identify the chain of work

cancelWorkByIdSync

void cancelWorkByIdSync (UUID id)

Cancels work with the given id in a synchronous fashion if it isn't finished. Note that cancellation is dependent on timing (for example, the work could have completed in a different thread just as you issue this call). Use getStatusByIdSync(UUID) to find out the actual state of the work after this call. This method is expected to be called from a background thread.

Parameters
id UUID: The id of the work

enqueueSync

void enqueueSync (WorkRequest... workRequest)

Enqueues one or more WorkRequest in a synchronous fashion. This method is expected to be called from a background thread and, upon successful execution, you can rely on that the work has been enqueued.

Parameters
workRequest WorkRequest: The Array of WorkRequest

enqueueSync

void enqueueSync (List<? extends WorkRequest> workRequest)

Enqueues the List of WorkRequest in a synchronous fashion. This method is expected to be called from a background thread and, upon successful execution, you can rely on that the work has been enqueued.

Parameters
workRequest List: The List of WorkRequest

getStatusByIdSync

WorkStatus getStatusByIdSync (UUID id)

Gets the WorkStatus of a given work id in a synchronous fashion. This method is expected to be called from a background thread.

Parameters
id UUID: The id of the work

Returns
WorkStatus A WorkStatus associated with id

getStatusesByTagSync

List<WorkStatus> getStatusesByTagSync (String tag)

Gets the WorkStatus for all work with a given tag in a synchronous fashion. This method is expected to be called from a background thread.

Parameters
tag String: The tag of the work

Returns
List<WorkStatus> A list of WorkStatus for work tagged with tag

getStatusesForUniqueWorkSync

List<WorkStatus> getStatusesForUniqueWorkSync (String uniqueWorkName)

Gets the WorkStatus for all work for the chain of work with a given unique name in a synchronous fashion. This method is expected to be called from a background thread.

Parameters
uniqueWorkName String: The unique name used to identify the chain of work

Returns
List<WorkStatus> A list of WorkStatus for work in the chain named uniqueWorkName