ScreenController

public class ScreenController
extends Object

java.lang.Object
   ↳ androidx.car.app.testing.ScreenController


ScreenController provides API that allows testing of a Screen.

This controller will allows:

Summary

Public constructors

ScreenController(Screen screen)

Creates a ScreenController to control a Screen for testing.

Public methods

Screen getScreen()

Returns the Screen being controlled.

Object getScreenResult()

Returns the result that was set via Screen.setResult(Object), or null if one was not set.

List<Template> getTemplatesReturned()

Returns all the Templates returned from Screen.onGetTemplate() for the Screen being controlled.

ScreenController moveToState(Lifecycle.State state)

Moves the Screen being controlled to the input state.

void reset()

Resets values tracked by this ScreenController.

Inherited methods

Public constructors

ScreenController

public ScreenController (Screen screen)

Creates a ScreenController to control a Screen for testing.

Parameters
screen Screen

Throws
NullPointerException if screen is null
IllegalArgumentException if screen was not created with a TestCarContext

Public methods

getScreen

public Screen getScreen ()

Returns the Screen being controlled.

Returns
Screen

getScreenResult

public Object getScreenResult ()

Returns the result that was set via Screen.setResult(Object), or null if one was not set.

Returns
Object

getTemplatesReturned

public List<Template> getTemplatesReturned ()

Returns all the Templates returned from Screen.onGetTemplate() for the Screen being controlled.

The templates are stored in the order in which they were returned from Screen.onGetTemplate(), where the first template in the list, is the first template returned.

The templates will be stored until reset() is called.

Returns
List<Template>

moveToState

public ScreenController moveToState (Lifecycle.State state)

Moves the Screen being controlled to the input state.

Note that moving the Screen up a state will also push the Screen onto the ScreenManager's screen stack if it isn't the current top.

Lifecycle.State.DESTROYED is a terminal state, and you cannot move to any other state after the Screen reaches that state.

Parameters
state Lifecycle.State

Returns
ScreenController

reset

public void reset ()

Resets values tracked by this ScreenController.