# TestScreenManager

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/testing/TestScreenManager "View this page in Java")

<br />

```
class TestScreenManager : ScreenManager
```

<br />

|---|---|-----------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                                            |||
| ↳ | [androidx.car.app.ScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager)                            ||
|   | ↳ | [androidx.car.app.testing.TestScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager) |

*** ** * ** ***

The[ScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager)that is used for testing.

This class will track the following usages of the[ScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager)throughout your test:

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

## Summary

|                                                                                                                                    ### Public functions                                                                                                                                    |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`!>` | [getScreensPushed](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#getScreensPushed())`()` Returns all the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)s pushed via[push](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#push(androidx.car.app.Screen)), and[pushForResult](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#pushForResult(androidx.car.app.Screen,androidx.car.app.OnScreenResultListener)).                                        |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`!>` | [getScreensRemoved](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#getScreensRemoved())`()` Returns all the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)s removed via[pop](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#pop()),[popTo](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#popTo(java.lang.String)), and[remove](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#remove(androidx.car.app.Screen)).     |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                                                                                                        | [hasScreens](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#hasScreens())`()` Returns`true`if the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)stack has any screens in it.                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [pop](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#pop())`()` Pops the top[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)from the stack.                                                                                                                                                                                                                                                                                                                                                                        |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [popTo](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#popTo(java.lang.String))`(marker: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Removes screens from the top of the stack until a[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)which has the given` marker`is found, or the root has been reached.                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [popToRoot](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#popToRoot())`()` Removes all screens from the stack until the root has been reached.                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [push](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#push(androidx.car.app.Screen))`(screen: `[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`)` Pushes the`screen`to the stack.                                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [pushForResult](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#pushForResult(androidx.car.app.Screen,androidx.car.app.OnScreenResultListener))`(` ` screen: `[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`,` ` onScreenResultListener: `[OnScreenResultListener](https://developer.android.com/reference/kotlin/androidx/car/app/OnScreenResultListener) `)` Pushes a[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen), for which you would like a result from, onto the stack. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [remove](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#remove(androidx.car.app.Screen))`(screen: `[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`)` Removes the`screen`from the stack.                                                                                                                                                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                              | [reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager#reset())`()` Resets the values tracked by this[TestScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager)and the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)stack.                                                                                                                                                                                                                                   |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.car.app.ScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager) |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)`)`[Collection](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html)`<`[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`!>` | [getScreenStack](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#getScreenStack())`()` Returns the copy of the current screen stack as a type[Collection](https://developer.android.com/reference/java/util/Collection.html) | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                                                                  | [getStackSize](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#getStackSize())`()` Returns the current stack size.                                                                                                           | | [Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)                                                                                                                                                                                                                             | [getTop](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#getTop())`()` Returns the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)that is at the top of the stack.                           | |

## Public functions

### getScreensPushed

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

```
fun getScreensPushed(): (Mutable)List<Screen!>
```

Returns all the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)s pushed via[push](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#push(androidx.car.app.Screen)), and[pushForResult](https://developer.android.com/reference/kotlin/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[reset](https://developer.android.com/reference/kotlin/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)  

```
fun getScreensRemoved(): (Mutable)List<Screen!>
```

Returns all the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)s removed via[pop](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#pop()),[popTo](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager#popTo(java.lang.String)), and[remove](https://developer.android.com/reference/kotlin/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[reset](https://developer.android.com/reference/kotlin/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)  

```
fun hasScreens(): Boolean
```

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

### pop

```
fun pop(): Unit
```

Pops the top[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)from the stack.

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

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

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

### popTo

```
fun popTo(marker: String): Unit
```

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

The root[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)will not be popped.

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

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

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

### popToRoot

```
fun popToRoot(): Unit
```

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

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

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

### push

```
fun push(screen: Screen): Unit
```

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[DESTROYED](https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED)state, this operation is a no-op.  

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

### pushForResult

```
fun pushForResult(
    screen: Screen,
    onScreenResultListener: OnScreenResultListener
): Unit
```

Pushes a[Screen](https://developer.android.com/reference/kotlin/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[onScreenResult](https://developer.android.com/reference/kotlin/androidx/car/app/OnScreenResultListener#onScreenResult(java.lang.Object))with the result that the pushed`screen`set via[setResult](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#setResult(java.lang.Object)).

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

|                                                                 Parameters                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `screen: `[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)                                                 | the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)to push on top of the stack                                                                                                                                    |
| `onScreenResultListener: `[OnScreenResultListener](https://developer.android.com/reference/kotlin/androidx/car/app/OnScreenResultListener) | the listener that will be executed with the result pushed by the`screen`through[setResult](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#setResult(java.lang.Object)). This callback will be executed on the main thread |

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

### remove

```
fun remove(screen: Screen): Unit
```

Removes the`screen`from the stack.

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

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

|                                                     Throws                                                      |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)   | if`screen`is`null`                           |
| [java.lang.IllegalStateException](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)  

```
fun reset(): Unit
```

Resets the values tracked by this[TestScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestScreenManager)and the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)stack.