# ScreenController

# ScreenController

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/ScreenController.java+class:androidx.car.app.testing.ScreenController)  
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/ScreenController "View this page in Java")

<br />

```
class ScreenController
```

<br />

*** ** * ** ***

[ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController)provides API that allows testing of a[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen).

This controller will allows:

- Moving a[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)through its different[State](https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State)s.
- Retrieving all[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)s returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate()). The values can be reset with[reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#reset()).

## Summary

|                                                                                                                                                                                 ### Public constructors                                                                                                                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#ScreenController(androidx.car.app.Screen))`(screen: `[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`)` Creates a ScreenController to control a[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)for testing. |

|                                                                                                                                         ### Public functions                                                                                                                                         |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)                                                                                                                                                                                                                     | [getScreen](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#getScreen())`()` Returns the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)being controlled.                                                                                                                                                                                                                                                  |
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?`                                                                                                                                                                                                                       | [getScreenResult](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#getScreenResult())`()` Returns the result that was set via[setResult](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#setResult(java.lang.Object)), or`null`if one was not set.                                                                                                                                                                   |
| `(`[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)`<`[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)`!>` | [getTemplatesReturned](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#getTemplatesReturned())`()` Returns all the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)s returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate())for the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)being controlled. |
| [ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController)                                                                                                                                                                                         | [moveToState](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#moveToState(androidx.lifecycle.Lifecycle.State))`(state: `[Lifecycle.State](https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State)`)` Moves the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)being controlled to the input`state`.                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                        | [reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#reset())`()` Resets values tracked by this[ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController).                                                                                                                                                                                                                            |

## Public constructors

### ScreenController

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

```
ScreenController(screen: Screen)
```

Creates a ScreenController to control a[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)for testing.  

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html)         | if`screen`is null                                                                                                                        |
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if`screen`was not created with a[TestCarContext](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestCarContext) |

## Public functions

### getScreen

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

```
fun getScreen(): Screen
```

Returns the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)being controlled.  

### getScreenResult

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

```
fun getScreenResult(): Any?
```

Returns the result that was set via[setResult](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#setResult(java.lang.Object)), or`null`if one was not set.  

### getTemplatesReturned

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

```
fun getTemplatesReturned(): (Mutable)List<Template!>
```

Returns all the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)s returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate())for the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)being controlled.

The templates are stored in the order in which they were returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate()), where the first template in the list, is the first template returned.

The templates will be stored until[reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController#reset())is called.  

### moveToState

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

```
fun moveToState(state: Lifecycle.State): ScreenController
```

Moves the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)being controlled to the input`state`.

Note that moving the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)up a state will also push the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)onto the[androidx.car.app.ScreenManager](https://developer.android.com/reference/kotlin/androidx/car/app/ScreenManager)'s screen stack if it isn't the current top.

[DESTROYED](https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#DESTROYED)is a terminal state, and you cannot move to any other state after the[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)reaches that state.  

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

### reset

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

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

Resets values tracked by this[ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController).