WorkerParameters


public final class WorkerParameters


Setup parameters for a ListenableWorker.

Summary

Public methods

@IntRange(from = 0) int

Gets the generation of this Worker.

@NonNull UUID

Gets the ID of the WorkRequest that created this ListenableWorker.

@NonNull Data

Gets the input data.

@Nullable 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.

@NonNull Set<String>

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

@NonNull List<String>

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

@NonNull List<Uri>

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

Extension functions

final boolean
final @NonNull WorkerParameters

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

final @NonNull WorkerParameters
WorkerParametersExtensions.usingRemoteService(
    @NonNull WorkerParameters receiver,
    @NonNull String workerClassName,
    @NonNull ComponentName componentName
)

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

Public methods

getGeneration

Added in 2.8.0
public @IntRange(from = 0) int getGeneration()

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
public @NonNull UUID getId()

Gets the ID of the WorkRequest that created this ListenableWorker.

Returns
@NonNull UUID

The ID of the creating WorkRequest

getInputData

Added in 1.0.0
public @NonNull Data getInputData()

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
@NonNull Data

The input data for this work

See also
setInputMerger

getNetwork

Added in 1.0.0
@RequiresApi(value = 28)
public @Nullable 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.

Returns
@Nullable Network

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

getRunAttemptCount

Added in 1.0.0
public @IntRange(from = 0) int getRunAttemptCount()

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
public @NonNull Set<StringgetTags()

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

Returns
@NonNull 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)
public @NonNull List<StringgetTriggeredContentAuthorities()

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

Returns
@NonNull List<String>

The list of content authorities that caused this Worker to execute

getTriggeredContentUris

Added in 1.0.0
@RequiresApi(value = 24)
public @NonNull List<UrigetTriggeredContentUris()

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

JobParameters#getTriggeredContentUris()} for relevant JobScheduler code.

Returns
@NonNull List<Uri>

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

Extension functions

WorkerParametersExtensions.isRemoteWorkRequest

public final boolean WorkerParametersExtensions.isRemoteWorkRequest(
    @NonNull WorkerParameters receiver
)
Returns
boolean

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

WorkerParametersExtensions.usingRemoteService

public final @NonNull WorkerParameters <T extends ListenableWorker> WorkerParametersExtensions.usingRemoteService(
    @NonNull WorkerParameters receiver,
    @NonNull ComponentName componentName
)

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

Parameters
<T extends ListenableWorker>

The ListenableWorker to delegate to.

@NonNull ComponentName componentName

The ComponentName that identifies the RemoteService that hosts the WorkRequest.

Returns
@NonNull WorkerParameters

A new instance of WorkerParameters

WorkerParametersExtensions.usingRemoteService

public final @NonNull WorkerParameters WorkerParametersExtensions.usingRemoteService(
    @NonNull WorkerParameters receiver,
    @NonNull String workerClassName,
    @NonNull ComponentName componentName
)

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

Parameters
@NonNull String workerClassName

The fully qualified class name of the ListenableWorker to delegate to

@NonNull ComponentName componentName

The ComponentName that identifies the RemoteService that hosts the WorkRequest.

Returns
@NonNull WorkerParameters

A new instance of WorkerParameters