# Class CarScreen

java.lang.Object
com.codename1.car.CarScreen

public abstract class CarScreen extends Object

One screen of the in-car experience -- the unit of the head-unit back stack. A screen produces a single `CarTemplate` from `onCreateTemplate()`; the framework pulls it when the screen is pushed or invalidated. Conceptually equivalent to `androidx.car.app.Screen`; on CarPlay a screen corresponds to one pushed `CPTemplate`.

    class AlbumsScreen extends CarScreen {
        protected CarTemplate onCreateTemplate() {
            CarListTemplate t = new CarListTemplate().setTitle("Albums");
            for (Album a : albums) {
                t.addRow(new CarRow(a.name).setImage(a.art)
                    .setBrowsable(true)
                    .setOnAction(ctx -> ctx.pushScreen(new TracksScreen(a))));
            }
            return t;
        }
    }

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CarScreen()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `dispatchCreate()`
  Framework entry point -- dispatches the `onCreate` lifecycle callback.
  `final CarTemplate`
  `dispatchCreateTemplate()`
  Framework entry point -- pulls the template, used by the platform `CarBridge`.
  `final void`
  `dispatchDestroy()`
  Framework entry point -- dispatches the `onDestroy` lifecycle callback.
  `final void`
  `dispatchPause()`
  Framework entry point -- dispatches the `onPause` lifecycle callback.
  `final void`
  `dispatchResume()`
  Framework entry point -- dispatches the `onResume` lifecycle callback.
  `final void`
  `finish()`
  Pops this screen off the stack (equivalent to `getContext().popScreen()` when this is the top screen).
  `final CarContext`
  `getContext()`
  Returns the context this screen is attached to, or null if it has not been pushed yet.
  `final void`
  `invalidate()`
  Rebuilds and re-renders this screen's template (after the model behind it changed).
  `protected void`
  `onCreate()`
  Lifecycle hook invoked once, when the screen is first pushed onto the stack, before its template is built.
  `protected abstract CarTemplate`
  `onCreateTemplate()`
  Builds the template to display for this screen.
  `protected void`
  `onDestroy()`
  Lifecycle hook invoked when the screen is popped and discarded.
  `protected void`
  `onPause()`
  Lifecycle hook invoked when the screen is covered by a pushed screen.
  `protected void`
  `onResume()`
  Lifecycle hook invoked when the screen becomes the visible top of stack.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CarScreen

    public CarScreen()

- ## Method Details

  - ### onCreateTemplate

    protected abstract CarTemplate onCreateTemplate()

    Builds the template to display for this screen. Called by the framework when the screen is pushed and again after `invalidate()`. Must return a non-null `CarTemplate`.

    ###### Returns

    the template to render on the head unit

  - ### onCreate

    protected void onCreate()
    Lifecycle hook invoked once, when the screen is first pushed onto the stack, before its template is built. Default is a no-op.

  - ### onResume

    protected void onResume()
    Lifecycle hook invoked when the screen becomes the visible top of stack. Default is a no-op.

  - ### onPause

    protected void onPause()
    Lifecycle hook invoked when the screen is covered by a pushed screen. Default is a no-op.

  - ### onDestroy

    protected void onDestroy()
    Lifecycle hook invoked when the screen is popped and discarded. Default is a no-op.

  - ### getContext

    public final CarContext getContext()

    Returns the context this screen is attached to, or null if it has not been pushed yet.

    ###### Returns

    the car context, or null

  - ### invalidate

    public final void invalidate()
    Rebuilds and re-renders this screen's template (after the model behind it changed). No-op when the screen is not currently attached or no head unit is connected.

  - ### finish

    public final void finish()
    Pops this screen off the stack (equivalent to `getContext().popScreen()` when this is the top screen). No-op when not attached.

  - ### dispatchCreateTemplate

    public final CarTemplate dispatchCreateTemplate()
    Framework entry point -- pulls the template, used by the platform `CarBridge`.

  - ### dispatchCreate

    public final void dispatchCreate()
    Framework entry point -- dispatches the `onCreate` lifecycle callback.

  - ### dispatchResume

    public final void dispatchResume()
    Framework entry point -- dispatches the `onResume` lifecycle callback.

  - ### dispatchPause

    public final void dispatchPause()
    Framework entry point -- dispatches the `onPause` lifecycle callback.

  - ### dispatchDestroy

    public final void dispatchDestroy()
    Framework entry point -- dispatches the `onDestroy` lifecycle callback.