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.

Summary

Nested types

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

Public constructors

Public methods

void
add(int priority)

Register a new task.

void
proceed(int priority)

Blocks until the task is allowed to proceed.

boolean
proceedNonBlocking(int priority)

A non-blocking variant of proceed.

void
proceedOrThrow(int priority)

A throwing variant of proceed.

void
remove(int priority)

Unregister a task.

Public constructors

PriorityTaskManager

public PriorityTaskManager()

Public methods

add

public void add(int priority)

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

Parameters
int priority

The priority of the task. Larger values indicate higher priorities.

proceed

public void proceed(int priority)

Blocks until the task is allowed to proceed.

Parameters
int priority

The priority of the task.

Throws
java.lang.InterruptedException

If the thread is interrupted.

proceedNonBlocking

public boolean proceedNonBlocking(int priority)

A non-blocking variant of proceed.

Parameters
int priority

The priority of the task.

Returns
boolean

Whether the task is allowed to proceed.

proceedOrThrow

public void proceedOrThrow(int priority)

A throwing variant of proceed.

Parameters
int priority

The priority of the task.

Throws
androidx.media3.common.PriorityTaskManager.PriorityTooLowException

If the task is not allowed to proceed.

remove

public void remove(int priority)

Unregister a task.

Parameters
int priority

The priority of the task.