RemoteListenableWorker

public abstract class RemoteListenableWorker
extends ListenableWorker

java.lang.Object
   ↳ androidx.work.ListenableWorker
     ↳ androidx.work.multiprocess.RemoteListenableWorker


Is an implementation of a ListenableWorker that can bind to a remote process.

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

The arguments (ARGUMENT_PACKAGE_NAME, ARGUMENT_CLASS_NAME) are used to determine the Service that the RemoteListenableWorker can bind to. startRemoteWork() is then subsequently called in the process that the Service is running in.

Summary

Constants

String ARGUMENT_CLASS_NAME

The ARGUMENT_PACKAGE_NAME, className together determine the ComponentName that the RemoteListenableWorker binds to before calling startRemoteWork().

String ARGUMENT_PACKAGE_NAME

The #ARGUMENT_PACKAGE_NAME, ARGUMENT_CLASS_NAME together determine the ComponentName that the RemoteListenableWorker binds to before calling startRemoteWork().

Public constructors

RemoteListenableWorker(Context appContext, WorkerParameters workerParams)

Public methods

void onStopped()

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

ListenableFuture<Void> setProgressAsync(Data data)

Updates ListenableWorker progress.

abstract ListenableFuture<ListenableWorker.Result> startRemoteWork()

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

final ListenableFuture<ListenableWorker.Result> startWork()

Override this method to start your actual background processing.

Inherited methods

Constants

ARGUMENT_CLASS_NAME

public static final String ARGUMENT_CLASS_NAME

The ARGUMENT_PACKAGE_NAME, className together determine the ComponentName that the RemoteListenableWorker binds to before calling startRemoteWork().

Constant Value: "androidx.work.impl.workers.RemoteListenableWorker.ARGUMENT_CLASS_NAME"

ARGUMENT_PACKAGE_NAME

public static final String ARGUMENT_PACKAGE_NAME

The #ARGUMENT_PACKAGE_NAME, ARGUMENT_CLASS_NAME together determine the ComponentName that the RemoteListenableWorker binds to before calling startRemoteWork().

Constant Value: "androidx.work.impl.workers.RemoteListenableWorker.ARGUMENT_PACKAGE_NAME"

Public constructors

RemoteListenableWorker

public RemoteListenableWorker (Context appContext, 
                WorkerParameters workerParams)

Parameters
appContext Context: The application Context

workerParams WorkerParameters: WorkerParameters to setup the internal state of this worker

Public methods

onStopped

public void onStopped ()

This method is invoked when this Worker has been told to stop. At this point, the 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.

setProgressAsync

public ListenableFuture<Void> setProgressAsync (Data data)

Updates ListenableWorker progress.

Parameters
data Data: The progress Data

Returns
ListenableFuture<Void> A ListenableFuture which resolves after progress is persisted. Cancelling this future is a no-op.

startRemoteWork

public abstract ListenableFuture<ListenableWorker.Result> startRemoteWork ()

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 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<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().

startWork

public final ListenableFuture<ListenableWorker.Result> startWork ()

Override this method to start your actual background processing. This method is called on the main thread.

A ListenableWorker has a well defined execution window to to finish its execution and return a ListenableWorker.Result. After this time has expired, the worker will be signalled to stop and its ListenableFuture will be cancelled.

The future will also be cancelled if this worker is stopped for any reason (see onStopped()).

Returns
ListenableFuture<ListenableWorker.Result> A ListenableFuture with the ListenableWorker.Result of the computation. If you cancel this Future, WorkManager will treat this unit of work as failed.