RxWorker
abstract class RxWorker : ListenableWorker
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
Worker
s. 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 androidx.work.ListenableWorker.Result
. After this time has expired, the worker will be signalled to stop.
Summary
Protected methods |
open Scheduler |
Returns the default background scheduler that RxWorker will use to subscribe.
|
Inherited functions |
From class ListenableWorker
Context |
getApplicationContext()
Gets the application android.content.Context .
|
ListenableFuture<ForegroundInfo!> |
getForegroundInfoAsync()
Return an instance of ForegroundInfo if the 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 ForegroundInfo . To update this notification subsequently, the application can use android.app.NotificationManager .
Starting in Android S and above, WorkManager manages this WorkRequest using an immediate job.
|
UUID |
getId()
Gets the ID of the WorkRequest that created this Worker.
|
Data |
getInputData()
Gets the input data. Note that in the case that there are multiple prerequisites for this Worker, the input data has been run through an InputMerger .
|
Network? |
getNetwork()
Gets the android.net.Network to use for this Worker. This method returns null if there is no network needed for this work request.
|
Int |
getRunAttemptCount()
Gets the current run attempt count for this work. Note that for periodic work, this value gets reset between periods.
|
MutableSet<String!> |
getTags()
Gets a java.util.Set of tags associated with this Worker's WorkRequest .
|
MutableList<String!> |
getTriggeredContentAuthorities()
Gets the list of content authorities that caused this Worker to execute. See JobParameters#getTriggeredContentAuthorities() for relevant JobScheduler code.
|
MutableList<Uri!> |
getTriggeredContentUris()
Gets the list of content android.net.Uri s that caused this Worker to execute. See JobParameters#getTriggeredContentUris() for relevant JobScheduler code.
|
Boolean |
isStopped()
Returns true if this Worker has been told to stop. This could be because of 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 and it is safe to stop the computation. WorkManager will retry the work at a later time if necessary.
|
ListenableFuture<Void!> |
setForegroundAsync(@NonNull foregroundInfo: ForegroundInfo)
This specifies that the 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 ListenableWorker signals completion by returning a Result .
Under the hood, WorkManager manages and runs a foreground service on your behalf to execute this WorkRequest, showing the notification provided in ForegroundInfo .
|
ListenableFuture<Void!> |
setProgressAsync(@NonNull data: Data)
Updates ListenableWorker progress.
|
|
Public