public final class CarContext

  1. Object
  2. CarContext

The live handle to a connected head unit. Created by the framework when a car connects and handed to CarApplication#onCreateRootScreen(CarContext) and to every CarActionListener. Use it to drive the head-unit back stack (pushScreen(CarScreen), popScreen()), surface transient messages (showToast(String)) and query driver-distraction limits.

The context delegates rendering to a platform com.codename1.car.spi.CarBridge. On the simulator and on ports without in-car projection the bridge is absent, so every method here is a harmless no-op and isConnected() returns false – application code never needs platform ifs.

Methods

public boolean isConnected()Returns true while a head unit is connected and rendering.
public CarScreen getTopScreen()Returns the screen currently at the top of the in-car back stack, or null if none.
public void pushScreen(CarScreen screen)Pushes a screen onto the head-unit back stack and renders it.
public void popScreen()Pops the top screen, returning to the one beneath it.
public void finish()Tears down the in-car experience and dismisses the app from the head unit.
public void showToast(String message)Shows a short transient message on the head unit.
public void showToast(String message, int durationSeconds)Shows a transient message on the head unit for a requested duration.
public int getListRowLimit()Returns the maximum rows the head unit will show in a CarListTemplate, or 0 if unknown.
public int getGridItemLimit()Returns the maximum items the head unit will show in a CarGridTemplate, or 0 if unknown.

Inherited methods

Method details

isConnected

public boolean isConnected()
Returns true while a head unit is connected and rendering.

getTopScreen

public CarScreen getTopScreen()
Returns the screen currently at the top of the in-car back stack, or null if none.

pushScreen

public void pushScreen(CarScreen screen)
Pushes a screen onto the head-unit back stack and renders it. The previous screen is paused.

Parameters

screen CarScreen
the screen to show

popScreen

public void popScreen()
Pops the top screen, returning to the one beneath it. No effect when only the root remains.

finish

public void finish()
Tears down the in-car experience and dismisses the app from the head unit.

showToast

public void showToast(String message)
Shows a short transient message on the head unit.

Parameters

message String
the text to display

showToast

public void showToast(String message, int durationSeconds)
Shows a transient message on the head unit for a requested duration.

Parameters

message String
the text to display
durationSeconds int
requested duration in seconds (the head unit may clamp it)

getListRowLimit

public int getListRowLimit()
Returns the maximum rows the head unit will show in a CarListTemplate, or 0 if unknown. Honour this when populating lists – rows beyond the limit are dropped by the platform.

Returns

the row limit, or 0 if unknown

getGridItemLimit

public int getGridItemLimit()
Returns the maximum items the head unit will show in a CarGridTemplate, or 0 if unknown.

Returns

the grid item limit, or 0 if unknown