public abstract class CarScreen
- Object
- CarScreen
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;
}
}
Constructors
public CarScreen() |
Methods
protected abstract CarTemplate onCreateTemplate() | Builds the template to display for this screen. |
protected void onCreate() | Lifecycle hook invoked once, when the screen is first pushed onto the stack, before its template is built. |
protected void onResume() | Lifecycle hook invoked when the screen becomes the visible top of stack. |
protected void onPause() | Lifecycle hook invoked when the screen is covered by a pushed screen. |
protected void onDestroy() | Lifecycle hook invoked when the screen is popped and discarded. |
public final CarContext getContext() | Returns the context this screen is attached to, or null if it has not been pushed yet. |
public final void invalidate() | Rebuilds and re-renders this screen’s template (after the model behind it changed). |
public final void finish() | Pops this screen off the stack (equivalent to getContext().popScreen() when this is the top screen). |
public final CarTemplate dispatchCreateTemplate() | Framework entry point – pulls the template, used by the platform CarBridge. |
public final void dispatchCreate() | Framework entry point – dispatches the onCreate lifecycle callback. |
public final void dispatchResume() | Framework entry point – dispatches the onResume lifecycle callback. |
public final void dispatchPause() | Framework entry point – dispatches the onPause lifecycle callback. |
public final void dispatchDestroy() | Framework entry point – dispatches the onDestroy lifecycle callback. |
Inherited methods
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.