# Class CarApplication

java.lang.Object
com.codename1.car.CarApplication

public abstract class CarApplication extends Object

The entry point an app implements to provide its in-car (Apple CarPlay / Google Android Auto) experience. Register a single instance with `Car#setApplication(CarApplication)` from your app's `init()` so it is in place before a head unit connects:

    public void init(Object ctx) {
        // ... normal app init ...
        Car.setApplication(new MyCarApplication());
    }

    class MyCarApplication extends CarApplication {
        public CarScreen onCreateRootScreen(CarContext context) {
            return new LibraryScreen();
        }
    }

Referencing any `com.codename1.car` type is what tells the build to wire the native in-car support (CarPlay scene + entitlement, Android Auto `CarAppService` + dependency); apps that never touch the package pay nothing. The app must also be in a head-unit-eligible category and declare it via build hints (see the category hints in the developer guide).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CarApplication()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `onCarConnected(CarContext context)`
  Invoked after the root screen is created, when the connection is fully established.
  `void`
  `onCarDisconnected()`
  Invoked when the head unit disconnects and the in-car experience ends.
  `abstract CarScreen`
  `onCreateRootScreen(CarContext context)`
  Builds the root screen shown when a head unit connects.

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### CarApplication

    public CarApplication()

- ## Method Details

  - ### onCreateRootScreen

    public abstract CarScreen onCreateRootScreen(CarContext context)

    Builds the root screen shown when a head unit connects. Called once per connection.

    ###### Parameters

    - `context`: the live car context for the connected head unit

    ###### Returns

    the root `CarScreen`; must be non-null

  - ### onCarConnected

    public void onCarConnected(CarContext context)

    Invoked after the root screen is created, when the connection is fully established. Default is a no-op; override for one-off setup (start playback, begin a location stream).

    ###### Parameters

    - `context`: the live car context

  - ### onCarDisconnected

    public void onCarDisconnected()
    Invoked when the head unit disconnects and the in-car experience ends. Default is a no-op; override to release car-only resources.