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

```
abstract class RemoteCoroutineWorker : RemoteListenableWorker
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [androidx.work.ListenableWorker](https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker) |||
|   | ↳ | [androidx.work.multiprocess.RemoteListenableWorker](https://developer.android.com/reference/kotlin/androidx/work/multiprocess/RemoteListenableWorker) ||
|   |   | ↳ | [androidx.work.multiprocess.RemoteCoroutineWorker](https://developer.android.com/reference/kotlin/androidx/work/multiprocess/RemoteCoroutineWorker) |

*** ** * ** ***

An implementation of `https://developer.android.com/reference/kotlin/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/kotlin/androidx/work/multiprocess/RemoteCoroutineWorker` needs additional arguments as part of its input `https://developer.android.com/reference/kotlin/androidx/work/Data`.

The arguments `https://developer.android.com/reference/kotlin/androidx/work/multiprocess/RemoteListenableWorker#ARGUMENT_PACKAGE_NAME()`, `https://developer.android.com/reference/kotlin/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/kotlin/androidx/work/multiprocess/RemoteCoroutineWorker` can bind to.

`https://developer.android.com/reference/kotlin/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/kotlin/androidx/work/multiprocess/RemoteCoroutineWorker#RemoteCoroutineWorker(android.content.Context,androidx.work.WorkerParameters)(context: https://developer.android.com/reference/android/content/Context.html, parameters: https://developer.android.com/reference/kotlin/androidx/work/WorkerParameters)` |

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

### Inherited functions

From [androidx.work.ListenableWorker](https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker) `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/java/lang/Void.html>` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#setForegroundAsync(androidx.work.ForegroundInfo)(foregroundInfo: https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo)`

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

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

Override this method to start your actual background processing.

### Inherited properties

From [androidx.work.ListenableWorker](https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker) `https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#applicationContext()` `open https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo>` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#foregroundInfoAsync()` `https://developer.android.com/reference/java/util/UUID.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#id()` `https://developer.android.com/reference/kotlin/androidx/work/Data` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#inputData()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#isStopped()` `https://developer.android.com/reference/android/net/Network.html?` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#network()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#runAttemptCount()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#stopReason()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#tags()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#triggeredContentAuthorities()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html<https://developer.android.com/reference/android/net/Uri.html>` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#triggeredContentUris()`

## Public constructors

### RemoteCoroutineWorker

Added in [2.6.0](https://developer.android.com/jetpack/androidx/releases/work#2.6.0)

```
RemoteCoroutineWorker(context: Context, parameters: WorkerParameters)
```

## Public functions

### doRemoteWork

```
abstract suspend fun doRemoteWork(): ListenableWorker.Result
```

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/kotlin/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/kotlin/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)

```
final 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 `https://developer.android.com/reference/kotlin/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)

```
suspend fun setProgress(data: Data): Unit
```

Updates the progress for the `https://developer.android.com/reference/kotlin/androidx/work/multiprocess/RemoteCoroutineWorker`. This is a suspending function unlike `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `data: https://developer.android.com/reference/kotlin/androidx/work/Data` | The progress `https://developer.android.com/reference/kotlin/androidx/work/Data` |

### startRemoteWork

```
open 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](https://d.android.com/reference/android/app/job/JobScheduler) to to finish its execution and return a `https://developer.android.com/reference/kotlin/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/kotlin/androidx/work/multiprocess/RemoteListenableWorker` will also be signalled to stop when its constraints are no longer met.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/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()`. |