# TestScreenManager

Artifact: [androidx.car.app:app-testing](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/testing/TestScreenManager.java+class:androidx.car.app.testing.TestScreenManager) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***


```
public class TestScreenManager extends ScreenManager
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.car.app.ScreenManager](https://developer.android.com/reference/androidx/car/app/ScreenManager) ||
|   | ↳ | [androidx.car.app.testing.TestScreenManager](https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager) |

*** ** * ** ***

The `https://developer.android.com/reference/androidx/car/app/ScreenManager` that is used for testing.

This class will track the following usages of the `https://developer.android.com/reference/androidx/car/app/ScreenManager` throughout your test:

- All the `https://developer.android.com/reference/androidx/car/app/Screen`s pushed via `https://developer.android.com/reference/androidx/car/app/ScreenManager#push(androidx.car.app.Screen)`, or `https://developer.android.com/reference/androidx/car/app/ScreenManager#pushForResult(androidx.car.app.Screen,androidx.car.app.OnScreenResultListener)`.
- All the `https://developer.android.com/reference/androidx/car/app/Screen`s removed via, `https://developer.android.com/reference/androidx/car/app/ScreenManager#pop()`, `https://developer.android.com/reference/androidx/car/app/ScreenManager#popTo(java.lang.String)`, or `https://developer.android.com/reference/androidx/car/app/ScreenManager#remove(androidx.car.app.Screen)`.

## Summary

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/car/app/Screen>` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#getScreensPushed()()` Returns all the `https://developer.android.com/reference/androidx/car/app/Screen`s pushed via `https://developer.android.com/reference/androidx/car/app/ScreenManager#push(androidx.car.app.Screen)`, and `https://developer.android.com/reference/androidx/car/app/ScreenManager#pushForResult(androidx.car.app.Screen,androidx.car.app.OnScreenResultListener)`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/car/app/Screen>` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#getScreensRemoved()()` Returns all the `https://developer.android.com/reference/androidx/car/app/Screen`s removed via `https://developer.android.com/reference/androidx/car/app/ScreenManager#pop()`, `https://developer.android.com/reference/androidx/car/app/ScreenManager#popTo(java.lang.String)`, and `https://developer.android.com/reference/androidx/car/app/ScreenManager#remove(androidx.car.app.Screen)`. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#hasScreens()()` Returns `true` if the `https://developer.android.com/reference/androidx/car/app/Screen` stack has any screens in it. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#pop()()` Pops the top `https://developer.android.com/reference/androidx/car/app/Screen` from the stack. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#popTo(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html marker)` Removes screens from the top of the stack until a `https://developer.android.com/reference/androidx/car/app/Screen` which has the given ` marker` is found, or the root has been reached. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#popToRoot()()` Removes all screens from the stack until the root has been reached. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#push(androidx.car.app.Screen)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Screen screen)` Pushes the `screen` to the stack. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#pushForResult(androidx.car.app.Screen,androidx.car.app.OnScreenResultListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Screen screen, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/OnScreenResultListener onScreenResultListener )` Pushes a `https://developer.android.com/reference/androidx/car/app/Screen`, for which you would like a result from, onto the stack. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#remove(androidx.car.app.Screen)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Screen screen)` Removes the `screen` from the stack. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#reset()()` Resets the values tracked by this `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager` and the `https://developer.android.com/reference/androidx/car/app/Screen` stack. |

| ### Inherited methods |
|---|
| From [androidx.car.app.ScreenManager](https://developer.android.com/reference/androidx/car/app/ScreenManager) |---|---| | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Collection.html<https://developer.android.com/reference/androidx/car/app/Screen>` | `https://developer.android.com/reference/androidx/car/app/ScreenManager#getScreenStack()()` Returns the copy of the current screen stack as a type `https://developer.android.com/reference/java/util/Collection.html` | | `int` | `https://developer.android.com/reference/androidx/car/app/ScreenManager#getStackSize()()` Returns the current stack size. | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Screen` | `https://developer.android.com/reference/androidx/car/app/ScreenManager#getTop()()` Returns the `https://developer.android.com/reference/androidx/car/app/Screen` that is at the top of the stack. | |

## Public methods

### getScreensPushed

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
public @NonNull List<Screen> getScreensPushed()
```

Returns all the `https://developer.android.com/reference/androidx/car/app/Screen`s pushed via `https://developer.android.com/reference/androidx/car/app/ScreenManager#push(androidx.car.app.Screen)`, and `https://developer.android.com/reference/androidx/car/app/ScreenManager#pushForResult(androidx.car.app.Screen,androidx.car.app.OnScreenResultListener)`.

The screens are stored in the order in which they were pushed, where the first screen in the list is the first screen that was pushed.

The screens will be stored until `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#reset()` is called.

### getScreensRemoved

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
public @NonNull List<Screen> getScreensRemoved()
```

Returns all the `https://developer.android.com/reference/androidx/car/app/Screen`s removed via `https://developer.android.com/reference/androidx/car/app/ScreenManager#pop()`, `https://developer.android.com/reference/androidx/car/app/ScreenManager#popTo(java.lang.String)`, and `https://developer.android.com/reference/androidx/car/app/ScreenManager#remove(androidx.car.app.Screen)`.

The screens are stored in the order in which they were removed, where the first screen in the list, is the first screen that was removed.

The screens will be stored until `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager#reset()` is called.

### hasScreens

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
public boolean hasScreens()
```

Returns `true` if the `https://developer.android.com/reference/androidx/car/app/Screen` stack has any screens in it.

### pop

```
public void pop()
```

Pops the top `https://developer.android.com/reference/androidx/car/app/Screen` from the stack.

If the top `https://developer.android.com/reference/androidx/car/app/Screen` is the only `https://developer.android.com/reference/androidx/car/app/Screen` in the stack, it will not be removed.

If the app's lifecycle is already in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, this operation is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### popTo

```
public void popTo(@NonNull String marker)
```

Removes screens from the top of the stack until a `https://developer.android.com/reference/androidx/car/app/Screen` which has the given `
marker` is found, or the root has been reached.

The root `https://developer.android.com/reference/androidx/car/app/Screen` will not be popped.

If the app's lifecycle is already in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, this operation is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `marker` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/Screen#setMarker(java.lang.String)` |   |

### popToRoot

```
public void popToRoot()
```

Removes all screens from the stack until the root has been reached.

If the app's lifecycle is already in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, this operation is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### push

```
public void push(@NonNull Screen screen)
```

Pushes the `screen` to the stack.

If the `screen` pushed is already in the stack it will be moved to the top of the stack.

If the app's lifecycle is already in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, this operation is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `screen` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### pushForResult

```
public void pushForResult(
    @NonNull Screen screen,
    @NonNull OnScreenResultListener onScreenResultListener
)
```

Pushes a `https://developer.android.com/reference/androidx/car/app/Screen`, for which you would like a result from, onto the stack.

When the given `screen` finishes, the `onScreenResultCallback` will receive a callback to `https://developer.android.com/reference/androidx/car/app/OnScreenResultListener#onScreenResult(java.lang.Object)` with the result that the pushed `screen` set via `https://developer.android.com/reference/androidx/car/app/Screen#setResult(java.lang.Object)`.

If the app's lifecycle is already in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, this operation is a no-op.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Screen screen` | the `https://developer.android.com/reference/androidx/car/app/Screen` to push on top of the stack |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/OnScreenResultListener onScreenResultListener` | the listener that will be executed with the result pushed by the `screen` through `https://developer.android.com/reference/androidx/car/app/Screen#setResult(java.lang.Object)`. This callback will be executed on the main thread |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if either the `screen` or the ` onScreenResultCallback` are `null` |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### remove

```
public void remove(@NonNull Screen screen)
```

Removes the `screen` from the stack.

If the `screen` is the only `https://developer.android.com/reference/androidx/car/app/Screen` in the stack, it will not be removed.

If the app's lifecycle is already in the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` state, this operation is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `screen` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the current thread is not the main thread |

### reset

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

```
public void reset()
```

Resets the values tracked by this `https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager` and the `https://developer.android.com/reference/androidx/car/app/Screen` stack.