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

*** ** * ** ***


```
public class ScreenController
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/car/app/testing/ScreenController` provides API that allows testing of a `https://developer.android.com/reference/androidx/car/app/Screen`.

This controller will allows:

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/testing/ScreenController#ScreenController(androidx.car.app.Screen)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Screen screen)` Creates a ScreenController to control a `https://developer.android.com/reference/androidx/car/app/Screen` for testing. |

| ### Public methods |
|---|---|
| `@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/testing/ScreenController#getScreen()()` Returns the `https://developer.android.com/reference/androidx/car/app/Screen` being controlled. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/car/app/testing/ScreenController#getScreenResult()()` Returns the result that was set via `https://developer.android.com/reference/androidx/car/app/Screen#setResult(java.lang.Object)`, or `null` if one was not set. |
| `@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/model/Template>` | `https://developer.android.com/reference/androidx/car/app/testing/ScreenController#getTemplatesReturned()()` Returns all the `https://developer.android.com/reference/androidx/car/app/model/Template`s returned from `https://developer.android.com/reference/androidx/car/app/Screen#onGetTemplate()` for the `https://developer.android.com/reference/androidx/car/app/Screen` being controlled. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/testing/ScreenController` | `https://developer.android.com/reference/androidx/car/app/testing/ScreenController#moveToState(androidx.lifecycle.Lifecycle.State)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State state)` Moves the `https://developer.android.com/reference/androidx/car/app/Screen` being controlled to the input `state`. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/ScreenController#reset()()` Resets values tracked by this `https://developer.android.com/reference/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)

```
public ScreenController(@NonNull Screen screen)
```

Creates a ScreenController to control a `https://developer.android.com/reference/androidx/car/app/Screen` for testing.

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

## Public methods

### getScreen

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

```
public @NonNull Screen getScreen()
```

Returns the `https://developer.android.com/reference/androidx/car/app/Screen` being controlled.

### getScreenResult

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

```
public @Nullable Object getScreenResult()
```

Returns the result that was set via `https://developer.android.com/reference/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)

```
public @NonNull List<Template> getTemplatesReturned()
```

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

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

The templates will be stored until `https://developer.android.com/reference/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)

```
public @NonNull ScreenController moveToState(@NonNull Lifecycle.State state)
```

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

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

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

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

### reset

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

```
public void reset()
```

Resets values tracked by this `https://developer.android.com/reference/androidx/car/app/testing/ScreenController`.