PriorityTaskManager


@UnstableApi
public final 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 methods

void
add(@C.Priority int priority)

Register a new task.

void
proceed(@C.Priority int priority)

Blocks until the task is allowed to proceed.

boolean

A non-blocking variant of proceed.

void
proceedOrThrow(@C.Priority int priority)

A throwing variant of proceed.

void
remove(@C.Priority int priority)

Unregister a task.

Public constructors

PriorityTaskManager

public PriorityTaskManager()

Public methods

add

public void add(@C.Priority int priority)

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 int priority

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

proceed

public void proceed(@C.Priority int priority)

Blocks until the task is allowed to proceed.

Parameters
@C.Priority int priority

The C.Priority of the task.

Throws
java.lang.InterruptedException

If the thread is interrupted.

proceedNonBlocking

public boolean proceedNonBlocking(@C.Priority int priority)

A non-blocking variant of proceed.

Parameters
@C.Priority int priority

The C.Priority of the task.

Returns
boolean

Whether the task is allowed to proceed.

proceedOrThrow

public void proceedOrThrow(@C.Priority int priority)

A throwing variant of proceed.

Parameters
@C.Priority int priority

The C.Priority of the task.

Throws
androidx.media3.common.PriorityTaskManager.PriorityTooLowException

If the task is not allowed to proceed.

remove

public void remove(@C.Priority int priority)

Unregister a task.

Parameters
@C.Priority int priority

The C.Priority of the task.