# RxWorker

Artifact: [androidx.work:work-rxjava3](https://developer.android.com/jetpack/androidx/releases/work) [View Source](https://cs.android.com/search?q=file:androidx/work/rxjava3/RxWorker.java+class:androidx.work.rxjava3.RxWorker) Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.0)

*** ** * ** ***

<br />

```
abstract class RxWorker : ListenableWorker
```

<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.rxjava3.RxWorker](https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker) |

*** ** * ** ***

RxJava3 interoperability Worker implementation.

When invoked by the `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`, it will call @`https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#createWork()` to get a `Single<Result>` subscribe to it.

By default, RxWorker will subscribe on the thread pool that runs `https://developer.android.com/reference/kotlin/androidx/work/WorkManager``https://developer.android.com/reference/kotlin/androidx/work/Worker`s. You can change this behavior by overriding `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#getBackgroundScheduler()` method.

An RxWorker is given a maximum of ten minutes 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.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/work/Worker` |   |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#RxWorker(android.content.Context,androidx.work.WorkerParameters)(appContext: https://developer.android.com/reference/android/content/Context.html, workerParams: https://developer.android.com/reference/kotlin/androidx/work/WorkerParameters)` |

| ### Public functions |
|---|---|
| `abstract http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result!>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#createWork()()` Override this method to define your actual work and return a `Single` of `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result` which will be subscribed by the `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`. |
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo!>` | `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#getForegroundInfo()()` Return an `Single` with an instance of `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` if the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is important to the user. |
| `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/rxjava3/RxWorker#getForegroundInfoAsync()()` Return an instance of `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` if the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is important to the user. |
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` | `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#setCompletableProgress(androidx.work.Data)(data: https://developer.android.com/reference/kotlin/androidx/work/Data)` Updates the progress for a `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker`. |
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` | `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#setForeground(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/kotlin/androidx/work/ListenableWorker.Result!>` | `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#startWork()()` Override this method to start your actual background processing. |

| ### Protected functions |
|---|---|
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html` | `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#getBackgroundScheduler()()` Returns the default background scheduler that `RxWorker` will use to subscribe. |

### Inherited functions

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#getApplicationContext()()`

Gets the application `https://developer.android.com/reference/android/content/Context.html`.
`https://developer.android.com/reference/java/util/UUID.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getId()()`

Gets the ID of the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` that created this Worker.
`https://developer.android.com/reference/kotlin/androidx/work/Data` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getInputData()()`

Gets the input data.
`https://developer.android.com/reference/android/net/Network.html?` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 28)
https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getNetwork()()`

Gets the `https://developer.android.com/reference/android/net/Network.html` to use for this Worker.
`@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getRunAttemptCount()()`

Gets the current run attempt count for this work.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 31)
https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getStopReason()()`

Returns a reason why this worker has been stopped.
`(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getTags()()`

Gets a `https://developer.android.com/reference/java/util/Set.html` of tags associated with this Worker's `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest`.
`(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getTriggeredContentAuthorities()()`

Gets the list of content authorities that caused this Worker to execute.
`(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/net/Uri.html!>` `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24)
https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#getTriggeredContentUris()()`

Gets the list of content `https://developer.android.com/reference/android/net/Uri.html`s that caused this Worker to execute.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#isStopped()()`

Returns `true` if this Worker has been told to stop.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#onStopped()()`

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

## Public constructors

### RxWorker

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

```
RxWorker(appContext: Context, workerParams: WorkerParameters)
```

| Parameters |
|---|---|
| `appContext: https://developer.android.com/reference/android/content/Context.html` | The application `https://developer.android.com/reference/android/content/Context.html` |
| `workerParams: https://developer.android.com/reference/kotlin/androidx/work/WorkerParameters` | Parameters to setup the internal state of this worker |

## Public functions

### createWork

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

```
@MainThread
abstract fun createWork(): Single<ListenableWorker.Result!>
```

Override this method to define your actual work and return a `Single` of `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result` which will be subscribed by the `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`.

If the returned `Single` fails, the worker will be considered as failed.

If the `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker` is cancelled by the `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` (e.g. due to a constraint change), `https://developer.android.com/reference/kotlin/androidx/work/WorkManager` will dispose the subscription immediately.

By default, subscription happens on the shared `https://developer.android.com/reference/kotlin/androidx/work/Worker` pool. You can change it by overriding `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#getBackgroundScheduler()`.

An RxWorker is given a maximum of ten minutes 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.

| Returns |
|---|---|
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result!>` | a `Single<Result>` that represents the work. |

### getForegroundInfo

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

```
fun getForegroundInfo(): Single<ForegroundInfo!>
```

Return an `Single` with an instance of `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` if the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is important to the user. In this case, WorkManager provides a signal to the OS that the process should be kept alive while this work is executing.

Prior to Android S, WorkManager manages and runs a foreground service on your behalf to execute the WorkRequest, showing the notification provided in the `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo`. To update this notification subsequently, the application can use `https://developer.android.com/reference/android/app/NotificationManager.html`.

Starting in Android S and above, WorkManager manages this WorkRequest using an immediate job.

| Returns |
|---|---|
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html<https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo!>` | A `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html` of `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` instance if the WorkRequest is marked immediate. For more information look at `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest.Builder#setExpedited(androidx.work.OutOfQuotaPolicy)`. |

### getForegroundInfoAsync

```
fun getForegroundInfoAsync(): ListenableFuture<ForegroundInfo!>
```

Return an instance of `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` if the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is important to the user. In this case, WorkManager provides a signal to the OS that the process should be kept alive while this work is executing.

Prior to Android S, WorkManager manages and runs a foreground service on your behalf to execute the WorkRequest, showing the notification provided in the `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo`. To update this notification subsequently, the application can use `https://developer.android.com/reference/android/app/NotificationManager.html`.

Starting in Android S and above, WorkManager manages this WorkRequest using an immediate job.

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo!>` | A `com.google.common.util.concurrent.ListenableFuture` of `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` instance if the WorkRequest is marked immediate. For more information look at `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest.Builder#setExpedited(androidx.work.OutOfQuotaPolicy)`. |

### setCompletableProgress

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

```
fun setCompletableProgress(data: Data): Completable
```

Updates the progress for a `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker`. This method returns a `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` similar to the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#setProgressAsync(androidx.work.Data)` API.

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

| Returns |
|---|---|
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` | The `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` |

### setForeground

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

```
fun setForeground(foregroundInfo: ForegroundInfo): Completable
```

This specifies that the `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest` is long-running or otherwise important. In this case, WorkManager provides a signal to the OS that the process should be kept alive if possible while this work is executing.

Calls to `setForegroundAsync` \*must\* complete before a `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker` signals completion by returning a `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result`.

Under the hood, WorkManager manages and runs a foreground service on your behalf to execute this WorkRequest, showing the notification provided in `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo`.

Calling `setForeground` will fail with an `https://developer.android.com/reference/java/lang/IllegalStateException.html` when the process is subject to foreground service restrictions. Consider using `https://developer.android.com/reference/kotlin/androidx/work/WorkRequest.Builder#setExpedited(androidx.work.OutOfQuotaPolicy)` and `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker#getForegroundInfo()` instead.

| Parameters |
|---|---|
| `foregroundInfo: https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` | The `https://developer.android.com/reference/kotlin/androidx/work/ForegroundInfo` |

| Returns |
|---|---|
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` | A `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Completable.html` which resolves after the `https://developer.android.com/reference/kotlin/androidx/work/rxjava3/RxWorker` transitions to running in the context of a foreground `https://developer.android.com/reference/android/app/Service.html`. |

### startWork

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/work#2.4.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](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 `com.google.common.util.concurrent.ListenableFuture` will be cancelled.

The future will also be cancelled if this worker is stopped for any reason (see `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker#onStopped()`).

| 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 `com.google.common.util.concurrent.ListenableFuture` with the `https://developer.android.com/reference/kotlin/androidx/work/ListenableWorker.Result` of the computation. If you cancel this Future, WorkManager will treat this unit of work as failed. |

## Protected functions

### getBackgroundScheduler

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

```
protected fun getBackgroundScheduler(): Scheduler
```

Returns the default background scheduler that `RxWorker` will use to subscribe.

The default implementation returns a Scheduler that uses the `https://developer.android.com/reference/java/util/concurrent/Executor.html` which was provided in `https://developer.android.com/reference/kotlin/androidx/work/WorkManager`'s `https://developer.android.com/reference/kotlin/androidx/work/Configuration` (or the default one it creates).

You can override this method to change the Scheduler used by RxWorker to start its subscription. It always observes the result of the `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html` in WorkManager's internal thread.

| Returns |
|---|---|
| `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html` | The default `http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Scheduler.html`. |