TaskRequest

@Serializable
data class TaskRequest(val id: String, val type: TaskType, val constraints: Constraints = Constraints(), val retryPolicy: RetryPolicy = RetryPolicy.None, val priority: TaskPriority = TaskPriority.NORMAL, val tags: Set<String> = emptySet(), val payload: String? = null, val label: String? = null)

Describes a background task to be scheduled.

Parameters

id

Unique identifier for the task. Used for registration, cancellation, and observation.

type

Whether this is a TaskType.OneTime or TaskType.Periodic task.

constraints

Platform constraints that must be satisfied before execution.

retryPolicy

How the task should be retried on failure.

priority

Execution priority hint. See TaskPriority.

tags

Optional set of string labels for group cancellation or filtering.

payload

Optional serialized data passed to the task handler via TaskExecutionContext.payload.

label

Optional human-readable display name for this task (used in logs and future foreground-service notifications). Defaults to id if not set.

Constructors

Link copied to clipboard
constructor(id: String, type: TaskType, constraints: Constraints = Constraints(), retryPolicy: RetryPolicy = RetryPolicy.None, priority: TaskPriority = TaskPriority.NORMAL, tags: Set<String> = emptySet(), payload: String? = null, label: String? = null)

Properties

Link copied to clipboard
Link copied to clipboard

Human-readable display name — falls back to id if label is not provided.

Link copied to clipboard
val id: String
Link copied to clipboard
val label: String? = null
Link copied to clipboard
val payload: String? = null
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
inline fun <T> TaskRequest.withPayload(data: T): TaskRequest

Encodes data as JSON and attaches it as the payload for this TaskRequest.