RemoteCoroutineWorker

public abstract class RemoteCoroutineWorker extends RemoteListenableWorker


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 androidx.work.ListenableWorker
final @NonNull Context

Gets the application android.content.Context.

@NonNull ListenableFuture<@NonNull ForegroundInfo>

Return an instance of ForegroundInfo if the WorkRequest is important to the user.

final @NonNull UUID

Gets the ID of the WorkRequest that created this Worker.

final @NonNull Data

Gets the input data.

final @Nullable Network
@RequiresApi(value = 28)
getNetwork()

Gets the android.net.Network to use for this Worker.

final @IntRange(from = 0) int

Gets the current run attempt count for this work.

final int

Returns a reason why this worker has been stopped.

final @NonNull Set<@NonNull String>

Gets a java.util.Set of tags associated with this Worker's WorkRequest.

final @NonNull List<@NonNull String>

Gets the list of content authorities that caused this Worker to execute.

final @NonNull List<@NonNull Uri>

Gets the list of content android.net.Uris that caused this Worker to execute.

final boolean

Returns true if this Worker has been told to stop.

final @NonNull ListenableFuture<@NonNull Void>

This specifies that the WorkRequest is long-running or otherwise important.

@NonNull ListenableFuture<@NonNull Void>

Updates ListenableWorker progress.

From androidx.work.multiprocess.RemoteListenableWorker
final @NonNull ListenableFuture<@NonNull ListenableWorker.Result>

Override this method to start your actual background processing.

Public constructors

RemoteCoroutineWorker

Added in 2.7.0
public RemoteCoroutineWorker(
    @NonNull Context context,
    @NonNull WorkerParameters parameters
)

Public methods

doRemoteWork

public abstract @NonNull 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

Added in 2.7.0
public final void onStopped()

This method is invoked when this Worker has been told to stop. At this point, the com.google.common.util.concurrent.ListenableFuture} 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

Added in 2.7.0
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

public @NonNull 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
@NonNull ListenableFuture<@NonNull ListenableWorker.Result>

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