PriorityTaskManager


@UnstableApi
class PriorityTaskManager


Allows tasks with associated priorities to control how they proceed relative to one another.

A task should call add to register with the manager and remove to unregister. A registered task will prevent tasks of lower priority from proceeding, and should call proceed, proceedNonBlocking or proceedOrThrow each time it wishes to check whether it is itself allowed to proceed.

It is recommended to use predefined priorities or priority values defined relative to those defaults.

Summary

Nested types

Thrown when task attempts to proceed when another registered task has a higher priority.

Public constructors

Public functions

Unit
add(@C.Priority priority: Int)

Register a new task.

Unit
proceed(@C.Priority priority: Int)

Blocks until the task is allowed to proceed.

Boolean

A non-blocking variant of proceed.

Unit

A throwing variant of proceed.

Unit
remove(@C.Priority priority: Int)

Unregister a task.

Public constructors

PriorityTaskManager

PriorityTaskManager()

Public functions

add

fun add(@C.Priority priority: Int): Unit

Register a new task. The task must call remove when done.

It is recommended to use predefined priorities or priority values defined relative to those defaults.

Parameters
@C.Priority priority: Int

The C.Priority of the task. Larger values indicate higher priorities.

proceed

fun proceed(@C.Priority priority: Int): Unit

Blocks until the task is allowed to proceed.

Parameters
@C.Priority priority: Int

The C.Priority of the task.

Throws
java.lang.InterruptedException

If the thread is interrupted.

proceedNonBlocking

fun proceedNonBlocking(@C.Priority priority: Int): Boolean

A non-blocking variant of proceed.

Parameters
@C.Priority priority: Int

The C.Priority of the task.

Returns
Boolean

Whether the task is allowed to proceed.

proceedOrThrow

fun proceedOrThrow(@C.Priority priority: Int): Unit

A throwing variant of proceed.

Parameters
@C.Priority priority: Int

The C.Priority of the task.

Throws
androidx.media3.common.PriorityTaskManager.PriorityTooLowException

If the task is not allowed to proceed.

remove

fun remove(@C.Priority priority: Int): Unit

Unregister a task.

Parameters
@C.Priority priority: Int

The C.Priority of the task.