# PriorityTaskManager

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/PriorityTaskManager.java+class:androidx.media3.common.PriorityTaskManager)

*** ** * ** ***


```
@UnstableApi
public final class PriorityTaskManager
```

<br />

*** ** * ** ***

Allows tasks with associated `https://developer.android.com/reference/androidx/media3/common/C.Priority` to control how they proceed relative to one another.

A task should call `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#add(int)` to register with the manager and `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#remove(int)` to unregister. A registered task will prevent tasks of lower priority from proceeding, and should call `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceed(int)`, `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceedNonBlocking(int)` or `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceedOrThrow(int)` each time it wishes to check whether it is itself allowed to proceed.

It is recommended to use predefined `https://developer.android.com/reference/androidx/media3/common/C.Priority` or priority values defined relative to those defaults.

## Summary

| ### Nested types |
|---|
| `public class https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager.PriorityTooLowException extends https://developer.android.com/reference/java/io/IOException.html` Thrown when task attempts to proceed when another registered task has a higher priority. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#PriorityTaskManager()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#add(int)(@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority)` Register a new task. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceed(int)(@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority)` Blocks until the task is allowed to proceed. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceedNonBlocking(int)(@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority)` A non-blocking variant of `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceed(int)`. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceedOrThrow(int)(@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority)` A throwing variant of `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceed(int)`. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#remove(int)(@https://developer.android.com/reference/androidx/media3/common/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 `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#remove(int)` when done.

It is recommended to use predefined `https://developer.android.com/reference/androidx/media3/common/C.Priority` or priority values defined relative to those defaults.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority` | The `https://developer.android.com/reference/androidx/media3/common/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority` | The `https://developer.android.com/reference/androidx/media3/common/C.Priority` of the task. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InterruptedException.html` | If the thread is interrupted. |

### proceedNonBlocking

```
public boolean proceedNonBlocking(@C.Priority int priority)
```

A non-blocking variant of `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceed(int)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority` | The `https://developer.android.com/reference/androidx/media3/common/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 `https://developer.android.com/reference/androidx/media3/common/PriorityTaskManager#proceed(int)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority` | The `https://developer.android.com/reference/androidx/media3/common/C.Priority` of the task. |

| Throws |
|---|---|
| `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/common/C.Priority int priority` | The `https://developer.android.com/reference/androidx/media3/common/C.Priority` of the task. |