Session
abstract class Session : LifecycleOwner
The base class for implementing a session for a car app.
Summary
Public constructors |
|---|
Session() |
Public functions |
|
|---|---|
CarContext |
Returns the |
Lifecycle |
|
Unit |
onCarConfigurationChanged(newConfiguration: Configuration)Notifies that the |
abstract Screen |
onCreateScreen(intent: Intent)Requests the first |
Unit |
onNewIntent(intent: Intent)Notifies that the car app has received a new |
Public functions
getCarContext
fun getCarContext(): CarContext
Returns the CarContext for this session.
The CarContext is not expected to be available until this session's Lifecycle.State 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
fun getLifecycle(): Lifecycle
Returns the Session's Lifecycle.
Here are some of the ways you can use the sessions's Lifecycle:
- Observe its
Lifecycleby callingaddObserver. You can use theandroidx.lifecycle.LifecycleObserverto take specific actions whenever theScreenreceives differentLifecycle.Events. - Use this
CarAppServiceto observeandroidx.lifecycle.LiveDatas that may drive the backing data for your application.
What each lifecycle related event means for a session:
- The session has just been launched, and this session is being initialized.
onCreateScreenwill be called at a point after this call. - The host is ready for this session to create the first
Screenso that it can display its template. - The application is now visible in the car screen.
- The user can now interact with this application.
- The user can no longer interact with this application.
- The application is no longer visible.
- The OS has now destroyed this
Sessioninstance, 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.
| See also | |
|---|---|
LifecycleObserver |
onCarConfigurationChanged
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
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 |
onNewIntent
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 |
| See also | |
|---|---|
startCarApp |