RemoteListenableWorker

abstract class RemoteListenableWorker : ListenableWorker

Known direct subclasses
RemoteCoroutineWorker

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


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 android.app.Service that the RemoteListenableWorker can bind to. startRemoteWork is then subsequently called in the process that the android.app.Service is running in.

Summary

Constants

const String!
ARGUMENT_CLASS_NAME = "androidx.work.impl.workers.RemoteListenableWorker.ARGUMENT_CLASS_NAME"

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

const String!
ARGUMENT_PACKAGE_NAME = "androidx.work.impl.workers.RemoteListenableWorker.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(
    appContext: Context,
    workerParams: WorkerParameters
)

Public functions

Unit

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

abstract ListenableFuture<ListenableWorker.Result!>

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

ListenableFuture<ListenableWorker.Result!>

Override this method to start your actual background processing.

Inherited functions

From androidx.work.ListenableWorker
Context

Gets the application android.content.Context.

ListenableFuture<ForegroundInfo!>

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

UUID

Gets the ID of the WorkRequest that created this Worker.

Data

Gets the input data.

Network?
@RequiresApi(value = 28)
getNetwork()

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

@IntRange(from = 0) Int

Gets the current run attempt count for this work.

Int

Returns a reason why this worker has been stopped.

(Mutable)Set<String!>

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

(Mutable)List<String!>

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

(Mutable)List<Uri!>

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

Boolean

Returns true if this Worker has been told to stop.

ListenableFuture<Void!>

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

ListenableFuture<Void!>

Updates ListenableWorker progress.

Constants

ARGUMENT_CLASS_NAME

Added in 2.7.0
const val ARGUMENT_CLASS_NAME = "androidx.work.impl.workers.RemoteListenableWorker.ARGUMENT_CLASS_NAME": String!

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

ARGUMENT_PACKAGE_NAME

Added in 2.7.0
const val ARGUMENT_PACKAGE_NAME = "androidx.work.impl.workers.RemoteListenableWorker.ARGUMENT_PACKAGE_NAME": String!

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

Public constructors

RemoteListenableWorker

Added in 2.7.0
RemoteListenableWorker(
    appContext: Context,
    workerParams: WorkerParameters
)
Parameters
appContext: Context

The application Context

workerParams: WorkerParameters

WorkerParameters to setup the internal state of this worker

Public functions

onStopped

@CallSuper
fun onStopped(): Unit

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.

startRemoteWork

Added in 2.7.0
abstract fun startRemoteWork(): ListenableFuture<ListenableWorker.Result!>

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<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

Added in 2.7.0
fun startWork(): ListenableFuture<ListenableWorker.Result!>

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 Result. After this time has expired, the worker will be signalled to stop and its com.google.common.util.concurrent.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 com.google.common.util.concurrent.ListenableFuture with the Result of the computation. If you cancel this Future, WorkManager will treat this unit of work as failed.