Session


abstract class Session : LifecycleOwner


The base class for implementing a session for a car app.

Summary

Public constructors

Public functions

CarContext

Returns the CarContext for this session.

Lifecycle

Returns the Session's Lifecycle.

Unit

Notifies that the CarContext's Configuration has changed.

abstract Screen

Requests the first Screen for the application.

Unit

Notifies that the car app has received a new Intent.

Public constructors

Session

Added in 1.0.0
Session()

Public functions

getCarContext

Added in 1.0.0
fun getCarContext(): CarContext

Returns the CarContext for this session.

The CarContext is not expected to be available until this session's is at least CREATED. Further, some instance methods within CarContext should not be called before this state has been reached. See the documentation in CarContext for details on any such restrictions.

See also
getLifecycle

getLifecycle

Added in 1.0.0
fun getLifecycle(): Lifecycle

Returns the Session's Lifecycle.

Here are some of the ways you can use the sessions's Lifecycle:

What each lifecycle related event means for a session:

ON_CREATE

The session has just been launched, and this session is being initialized. onCreateScreen will be called at a point after this call.

onCreateScreen

The host is ready for this session to create the first Screen so that it can display its template.

ON_START

The application is now visible in the car screen.

ON_RESUME

The user can now interact with this application.

ON_PAUSE

The user can no longer interact with this application.

ON_STOP

The application is no longer visible.

ON_DESTROY

The OS has now destroyed this Session instance, and it is no longer valid.

Listeners that are added in ON_START, should be removed in ON_STOP.

Listeners that are added in ON_CREATE should be removed in ON_DESTROY.

Note lifecycle callbacks will be executed on the main thread.

onCarConfigurationChanged

Added in 1.0.0
fun onCarConfigurationChanged(newConfiguration: Configuration): Unit

Notifies that the CarContext's Configuration has changed.

At the time that this function is called, the CarContext's resources object will have been updated to return resource values matching the new configuration.

Called by the system, do not call this method directly.

See also
CarContext

onCreateScreen

Added in 1.0.0
abstract fun onCreateScreen(intent: Intent): Screen

Requests the first Screen for the application.

Once the method returns, onGetTemplate will be called on the Screen returned, and the app will be displayed on the car screen.

To pre-seed a back stack, you can push Screens onto the stack, via push during this method call.

Called by the system, do not call this method directly.

Parameters
intent: Intent

the intent that was used to start this app. If the app was started with a call to startCarApp, this intent will be equal to the intent passed to that method

onNewIntent

Added in 1.0.0
fun onNewIntent(intent: Intent): Unit

Notifies that the car app has received a new Intent.

Once the method returns, onGetTemplate will be called on the Screen that is on top of the Screen stack managed by the ScreenManager, and the app will be displayed on the car screen.

Often used to update the current Screen or pushing a new one on the stack, based off of the information in the intent.

Called by the system, do not call this method directly.

Parameters
intent: Intent

the intent that was used to start this app. If the app was started with a call to startCarApp, this intent will be equal to the intent passed to that method

See also
startCarApp