RemoteCoroutineWorker

public abstract class RemoteCoroutineWorker extends ListenableWorker, RemoteListenableWorker

Object
   ↳ ListenableWorker
     ↳ RemoteListenableWorker
       ↳ RemoteCoroutineWorker

An implementation of RemoteListenableWorker that can bind to a remote process.

To be able to bind to a remote process, A RemoteCoroutineWorker needs additional arguments as part of its input androidx.work.Data.

The arguments RemoteListenableWorker.ARGUMENT_PACKAGE_NAME, RemoteListenableWorker.ARGUMENT_CLASS_NAME are used to determine the android.app.Service that the RemoteCoroutineWorker can bind to.

doRemoteWork is then subsequently called in the process that the android.app.Service is running in.

Summary

Public constructors

RemoteCoroutineWorker(
    @NonNull Context context,
    @NonNull WorkerParameters parameters
)

Public methods

abstract @NonNull ListenableWorker.Result

Override this method to define the work that needs to run in the remote process.

final void

This method is invoked when this Worker has been told to stop.

final void

Updates the progress for the RemoteCoroutineWorker.

@NonNull ListenableFuture<@NonNull ListenableWorker.Result>

Override this method to define the work that needs to run in the remote process.

Inherited methods

From class ListenableWorker
final @NonNull Context
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) @NonNull Executor
@NonNull ListenableFuture<@NonNull ForegroundInfo>
final @NonNull UUID
final @NonNull Data
final @RequiresApi(value = "28") @Nullable Network
final @IntRange(from = "0") int
final @NonNull Set<@NonNull String>
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) @NonNull TaskExecutor
final @RequiresApi(value = "24") @NonNull List<@NonNull String>
final @RequiresApi(value = "24") @NonNull List<@NonNull Uri>
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) @NonNull WorkerFactory
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) boolean
final boolean
final @RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) boolean
final @NonNull ListenableFuture<@NonNull Void>
@RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) void
setRunInForeground(boolean runInForeground)
final @RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) void
final @RestrictTo(value = RestrictTo.Scope.LIBRARY_GROUP) void
From class RemoteListenableWorker
@NonNull @Override ListenableFuture<@NonNull Void>

Updates ListenableWorker progress.

final @Override @NonNull ListenableFuture<@NonNull ListenableWorker.Result>

Override this method to start your actual background processing.

Public fields

mExecutor

@NonNull
public final @NonNull Executor mExecutor

mWorkManager

@NonNull
public final @NonNull WorkManagerImpl mWorkManager

mWorkerClassName

@Nullable
public final @Nullable String mWorkerClassName

mWorkerParameters

@NonNull
public final @NonNull WorkerParameters mWorkerParameters

Public constructors

RemoteCoroutineWorker

public final RemoteCoroutineWorker(
    @NonNull Context context,
    @NonNull WorkerParameters parameters
)

Public methods

doRemoteWork

@NonNull
public abstract ListenableWorker.Result doRemoteWork()

Override this method to define the work that needs to run in the remote process. Dispatchers.Default is the coroutine dispatcher being used when this method is called.

A RemoteCoroutineWorker has a well defined execution window to finish its execution and return a androidx.work.ListenableWorker.Result. Note that the execution window also includes the cost of binding to the remote process.

onStopped

@NonNull
public final void onStopped()

This method is invoked when this Worker has been told to stop. At this point, the returned by the instance of #startWork() is also cancelled. This could happen due to an explicit cancellation signal by the user, or because the system has decided to preempt the task. In these cases, the results of the work will be ignored by WorkManager. All processing in this method should be lightweight - there are no contractual guarantees about which thread will invoke this call, so this should not be a long-running or blocking operation.

setProgress

@NonNull
public final void setProgress(@NonNull Data data)

Updates the progress for the RemoteCoroutineWorker. This is a suspending function unlike setProgressAsync API which returns a ListenableFuture.

Parameters
@NonNull Data data

The progress Data

startRemoteWork

@NonNull
public ListenableFuture<@NonNull ListenableWorker.ResultstartRemoteWork()

Override this method to define the work that needs to run in the remote process. This method is called on the main thread.

A ListenableWorker has a well defined execution window to to finish its execution and return a androidx.work.ListenableWorker.Result. After this time has expired, the worker will be signalled to stop and its ListenableFuture will be cancelled. Note that the execution window also includes the cost of binding to the remote process.

The RemoteListenableWorker will also be signalled to stop when its constraints are no longer met.

Returns
ListenableFuture<@NonNull ListenableWorker.Result>

A ListenableFuture with the {@code Result} of the computation. If you cancel this Future, WorkManager will treat this unit of work as a {@code Result#failure()}.