public abstract class RxWorker
extends ListenableWorker

   ↳ androidx.work.ListenableWorker
     ↳ androidx.work.RxWorker

RxJava2 interoperability Worker implementation.

When invoked by the WorkManager, it will call @createWork() to get a Single<Result> subscribe to it.

By default, RxWorker will subscribe on the thread pool that runs WorkManager Workers. You can change this behavior by overriding getBackgroundScheduler() method.

An RxWorker is given a maximum of ten minutes to finish its execution and return a ListenableWorker.Result. After this time has expired, the worker will be signalled to stop.

See also:


Public constructors

RxWorker(Context appContext, WorkerParameters workerParams)

Public methods

abstract Single<ListenableWorker.Result> createWork()

Override this method to define your actual work and return a Single of ListenableWorker.Result which will be subscribed by the WorkManager.

Single<ForegroundInfo> getForegroundInfo()

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

ListenableFuture<ForegroundInfo> getForegroundInfoAsync()

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

void onStopped()

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

final Completable setCompletableProgress(Data data)

Updates the progress for a RxWorker.

final Completable setForeground(ForegroundInfo foregroundInfo)

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

final Single<Void> setProgress(Data data)

This method is deprecated. This method is being deprecated because it is impossible to signal success via a `Single<Void>` type. A Completable should have been used.

Use setCompletableProgress(Data) instead.

ListenableFuture<ListenableWorker.Result> startWork()

Override this method to start your actual background processing.

Protected methods

Scheduler getBackgroundScheduler()

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

Inherited methods