WorkerParameters


class WorkerParameters


Setup parameters for a ListenableWorker.

Summary

Public functions

@IntRange(from = 0) Int

Gets the generation of this Worker.

UUID

Gets the ID of the WorkRequest that created this ListenableWorker.

Data

Gets the input data.

Network?
@RequiresApi(value = 28)
getNetwork()

Gets the android.net.Network to use for this Worker.

@IntRange(from = 0) Int

Gets the current run attempt count for this work.

(Mutable)Set<String!>

Gets a java.util.Set of tags associated with this Worker's WorkRequest.

(Mutable)List<String!>

Gets the list of content authorities that caused this Worker to execute.

(Mutable)List<Uri!>

Gets the list of content android.net.Uris that caused this Worker to execute.

Extension functions

Boolean
inline WorkerParameters

Returns a new instance of WorkerParameters representing a WorkRequest that can run in a process corresponding to the provided ComponentName.

WorkerParameters
WorkerParameters.usingRemoteService(
    workerClassName: String,
    componentName: ComponentName
)

Returns a new instance of WorkerParameters representing a WorkRequest that can run in a process corresponding to the provided ComponentName.

Public functions

getGeneration

Added in 2.8.0
fun getGeneration(): @IntRange(from = 0) Int

Gets the generation of this Worker.

A work has multiple generations, if it was updated via updateWork or enqueueUniquePeriodicWork using UPDATE. This worker can possibly be of an older generation rather than latest known, if an update has happened while this worker is running.

Returns
@IntRange(from = 0) Int

a generation of this work.

getId

Added in 1.0.0
fun getId(): UUID

Gets the ID of the WorkRequest that created this ListenableWorker.

Returns
UUID

The ID of the creating WorkRequest

getInputData

Added in 1.0.0
fun getInputData(): Data

Gets the input data. Note that in the case that there are multiple prerequisites for this ListenableWorker, the input data has been run through an InputMerger.

Returns
Data

The input data for this work

See also
setInputMerger

getNetwork

Added in 1.0.0
@RequiresApi(value = 28)
fun getNetwork(): Network?

Gets the android.net.Network to use for this Worker. This method returns null if there is no network needed for this work request.

Returns
Network?

The android.net.Network specified by the OS to be used with this Worker

getRunAttemptCount

Added in 1.0.0
fun getRunAttemptCount(): @IntRange(from = 0) Int

Gets the current run attempt count for this work. Note that for periodic work, this value gets reset between periods.

Returns
@IntRange(from = 0) Int

The current run attempt count for this work.

getTags

Added in 1.0.0
fun getTags(): (Mutable)Set<String!>

Gets a java.util.Set of tags associated with this Worker's WorkRequest.

Returns
(Mutable)Set<String!>

The java.util.Set of tags associated with this Worker's WorkRequest

See also
addTag

getTriggeredContentAuthorities

Added in 1.0.0
@RequiresApi(value = 24)
fun getTriggeredContentAuthorities(): (Mutable)List<String!>

Gets the list of content authorities that caused this Worker to execute. See JobParameters#getTriggeredContentAuthorities() for relevant JobScheduler code.

Returns
(Mutable)List<String!>

The list of content authorities that caused this Worker to execute

getTriggeredContentUris

Added in 1.0.0
@RequiresApi(value = 24)
fun getTriggeredContentUris(): (Mutable)List<Uri!>

Gets the list of content android.net.Uris that caused this Worker to execute. See

JobParameters#getTriggeredContentUris()} for relevant JobScheduler code.

Returns
(Mutable)List<Uri!>

The list of content android.net.Uris that caused this Worker to execute

Extension functions

isRemoteWorkRequest

fun WorkerParameters.isRemoteWorkRequest(): Boolean
Returns
Boolean

true if and only if the instance of WorkerParameters corresponds to a WorkRequest that runs in a remote process.

usingRemoteService

inline fun <T : ListenableWorker> WorkerParameters.usingRemoteService(
    componentName: ComponentName
): WorkerParameters

Returns a new instance of WorkerParameters representing a WorkRequest that can run in a process corresponding to the provided ComponentName.

Parameters
<T : ListenableWorker>

The ListenableWorker to delegate to.

componentName: ComponentName

The ComponentName that identifies the RemoteService that hosts the WorkRequest.

Returns
WorkerParameters

A new instance of WorkerParameters

usingRemoteService

fun WorkerParameters.usingRemoteService(
    workerClassName: String,
    componentName: ComponentName
): WorkerParameters

Returns a new instance of WorkerParameters representing a WorkRequest that can run in a process corresponding to the provided ComponentName.

Parameters
workerClassName: String

The fully qualified class name of the ListenableWorker to delegate to

componentName: ComponentName

The ComponentName that identifies the RemoteService that hosts the WorkRequest.

Returns
WorkerParameters

A new instance of WorkerParameters