# RemoteCoroutineWorker

Artifact: [androidx.work:work-multiprocess](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/multiprocess/RemoteCoroutineWorker.kt+class:androidx.work.multiprocess.RemoteCoroutineWorker) Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/work#2.6.0)

*** ** * ** ***

<br />

```
public abstract class RemoteCoroutineWorker extends RemoteListenableWorker
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [androidx.work.ListenableWorker](https://developer.android.com/reference/androidx/work/ListenableWorker) |||
|   | ↳ | [androidx.work.multiprocess.RemoteListenableWorker](https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker) ||
|   |   | ↳ | [androidx.work.multiprocess.RemoteCoroutineWorker](https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker) |

*** ** * ** ***

An implementation of `https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker` that can bind to a remote process.

To be able to bind to a remote process, A `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker` needs additional arguments as part of its input `https://developer.android.com/reference/androidx/work/Data`.

The arguments `https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker#ARGUMENT_PACKAGE_NAME()`, `https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker#ARGUMENT_CLASS_NAME()` are used to determine the `https://developer.android.com/reference/android/app/Service.html` that the `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker` can bind to.

`https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker#doRemoteWork()` is then subsequently called in the process that the `https://developer.android.com/reference/android/app/Service.html` is running in.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker#RemoteCoroutineWorker(android.content.Context,androidx.work.WorkerParameters)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/WorkerParameters parameters )` |

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ListenableWorker.Result` | `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker#doRemoteWork()()` Override this method to define the work that needs to run in the remote process. |
| `final void` | `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker#onStopped()()` This method is invoked when this Worker has been told to stop. |
| `final void` | `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker#setProgress(androidx.work.Data)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Data data)` Updates the progress for the `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ListenableWorker.Result>` | `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker#startRemoteWork()()` Override this method to define the work that needs to run in the remote process. |

### Inherited methods

From [androidx.work.ListenableWorker](https://developer.android.com/reference/androidx/work/ListenableWorker) `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/androidx/work/ListenableWorker#getApplicationContext()()` `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ForegroundInfo>` `https://developer.android.com/reference/androidx/work/ListenableWorker#getForegroundInfoAsync()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/UUID.html` `https://developer.android.com/reference/androidx/work/ListenableWorker#getId()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/Data` `https://developer.android.com/reference/androidx/work/ListenableWorker#getInputData()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/net/Network.html` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 28)
https://developer.android.com/reference/androidx/work/ListenableWorker#getNetwork()()` `final @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int` `https://developer.android.com/reference/androidx/work/ListenableWorker#getRunAttemptCount()()` `final int` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31)
https://developer.android.com/reference/androidx/work/ListenableWorker#getStopReason()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html>` `https://developer.android.com/reference/androidx/work/ListenableWorker#getTags()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html>` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/androidx/work/ListenableWorker#getTriggeredContentAuthorities()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html>` `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/androidx/work/ListenableWorker#getTriggeredContentUris()()` `final boolean` `https://developer.android.com/reference/androidx/work/ListenableWorker#isStopped()()` `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Void.html>` `https://developer.android.com/reference/androidx/work/ListenableWorker#setForegroundAsync(androidx.work.ForegroundInfo)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/ForegroundInfo foregroundInfo)`

This specifies that the `https://developer.android.com/reference/androidx/work/WorkRequest` is long-running or otherwise important.
`@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Void.html>` `https://developer.android.com/reference/androidx/work/ListenableWorker#setProgressAsync(androidx.work.Data)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/work/Data data)`

Updates `https://developer.android.com/reference/androidx/work/ListenableWorker` progress.
From [androidx.work.multiprocess.RemoteListenableWorker](https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker) `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ListenableWorker.Result>` `https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker#startWork()()`

Override this method to start your actual background processing.

## Public constructors

### RemoteCoroutineWorker

Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/work#2.6.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. `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-default.html` is the coroutine dispatcher being used when this method is called.

A `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker` has a well defined [execution window](https://d.android.com/reference/android/app/job/JobScheduler) to finish its execution and return a `https://developer.android.com/reference/androidx/work/ListenableWorker.Result`. Note that the execution window also includes the cost of binding to the remote process.

### onStopped

Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/work#2.6.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 `https://developer.android.com/reference/androidx/work/ListenableWorker#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.6.0](https://developer.android.com/jetpack/androidx/releases/work#2.6.0)

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

Updates the progress for the `https://developer.android.com/reference/androidx/work/multiprocess/RemoteCoroutineWorker`. This is a suspending function unlike `https://developer.android.com/reference/androidx/work/ListenableWorker#setProgressAsync(androidx.work.Data)` API which returns a `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/Data data` | The progress `https://developer.android.com/reference/androidx/work/Data` |

### startRemoteWork

```
public @NonNull ListenableFuture<@NonNull 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](https://d.android.com/reference/android/app/job/JobScheduler) to to finish its execution and return a `https://developer.android.com/reference/androidx/work/ListenableWorker.Result`. After this time has expired, the worker will be signalled to stop and its `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` will be cancelled. Note that the execution window also includes the cost of binding to the remote process.

The `https://developer.android.com/reference/androidx/work/multiprocess/RemoteListenableWorker` will also be signalled to stop when its constraints are no longer met.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/work/ListenableWorker.Result>` | A `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` with the `Result` of the computation. If you cancel this Future, WorkManager will treat this unit of work as a `Result#failure()`. |