Session
public
abstract
class
Session
extends Object
implements
LifecycleOwner
| java.lang.Object | |
| ↳ | androidx.car.app.Session |
The base class for implementing a session for a car app.
Summary
Public constructors | |
|---|---|
Session()
|
|
Public methods | |
|---|---|
final
CarContext
|
getCarContext()
Returns the |
Lifecycle
|
getLifecycle()
|
void
|
onCarConfigurationChanged(Configuration newConfiguration)
Notifies that the |
abstract
Screen
|
onCreateScreen(Intent intent)
Requests the first |
void
|
onNewIntent(Intent intent)
Notifies that the car app has received a new |
Inherited methods | |
|---|---|
Public constructors
Session
public Session ()
Public methods
getCarContext
public final CarContext getCarContext ()
Returns the CarContext for this session.
The CarContext is not expected to be available until this session's Lifecycle.State is at least Lifecycle.State.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.
| Returns | |
|---|---|
CarContext |
|
See also:
getLifecycle
public Lifecycle getLifecycle ()
Returns the Session's Lifecycle.
Here are some of the ways you can use the sessions's Lifecycle:
- Observe its
Lifecycleby callingLifecycle.addObserver(LifecycleObserver). You can use theLifecycleObserverto take specific actions whenever theScreenreceives differentLifecycle.Events. - Use this
CarAppServiceto observeLiveDatas that may drive the backing data for your application.
What each lifecycle related event means for a session:
Lifecycle.Event.ON_CREATE- The session has just been launched, and this session is being initialized.
onCreateScreen(Intent)will be called at a point after this call. onCreateScreen(Intent)- The host is ready for this session to create the first
Screenso that it can display its template. Lifecycle.Event.ON_START- The application is now visible in the car screen.
Lifecycle.Event.ON_RESUME- The user can now interact with this application.
Lifecycle.Event.ON_PAUSE- The user can no longer interact with this application.
Lifecycle.Event.ON_STOP- The application is no longer visible.
Lifecycle.Event.ON_DESTROY- The OS has now destroyed this
Sessioninstance, and it is no longer valid.
Listeners that are added in Lifecycle.Event.ON_START, should be removed in Lifecycle.Event.ON_STOP.
Listeners that are added in Lifecycle.Event.ON_CREATE should be removed in Lifecycle.Event.ON_DESTROY.
Note lifecycle callbacks will be executed on the main thread.
| Returns | |
|---|---|
Lifecycle |
The lifecycle of the provider. |
See also:
onCarConfigurationChanged
public void onCarConfigurationChanged (Configuration newConfiguration)
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.
| Parameters | |
|---|---|
newConfiguration |
Configuration |
See also:
onCreateScreen
public abstract Screen onCreateScreen (Intent intent)
Requests the first Screen for the application.
Once the method returns, Screen.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 ScreenManager.push(Screen) 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 CarContext.startCarApp(Intent), this intent will be equal to
the intent passed to that method
|
| Returns | |
|---|---|
Screen |
|
onNewIntent
public void onNewIntent (Intent intent)
Notifies that the car app has received a new Intent.
Once the method returns, Screen.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 syst