AppManager


class AppManager : Manager

Known direct subclasses
TestAppManager

The AppManager that is used for testing.


Manages the communication between the app and the host.

Summary

Public functions

Unit
@RequiresCarApi(value = 5)
dismissAlert(alertId: Int)

Dismisses the alert with the given id.

Unit

Requests the current template to be invalidated, which eventually triggers a call to onGetTemplate to get the new template to display.

Unit

Sets the SurfaceCallback to get changes and updates to the surface on which the app can draw custom content, or null to reset the listener.

Unit
@RequiresCarApi(value = 5)
showAlert(alert: Alert)

Shows an alert on the car screen.

Unit
showToast(text: CharSequence, duration: Int)

Shows a toast on the car screen.

Public functions

dismissAlert

Added in 1.2.0
@RequiresCarApi(value = 5)
fun dismissAlert(alertId: Int): Unit

Dismisses the alert with the given id.

This is a no-op if there is not an active alert with the given id

Parameters
alertId: Int

the id of the alert that should be dismissed

Throws
androidx.car.app.HostException

if the remote call fails

invalidate

Added in 1.0.0
fun invalidate(): Unit

Requests the current template to be invalidated, which eventually triggers a call to onGetTemplate to get the new template to display.

Throws
androidx.car.app.HostException

if the remote call fails

setSurfaceCallback

Added in 1.0.0
fun setSurfaceCallback(surfaceCallback: SurfaceCallback?): Unit

Sets the SurfaceCallback to get changes and updates to the surface on which the app can draw custom content, or null to reset the listener.

This call requires the androidx.car.app.ACCESS_SURFACE permission to be declared.

The Surface can be used to draw custom content such as a navigation app's map.

Note that the listener relates to UI events and will be executed on the main thread using getMainLooper.

Throws
java.lang.SecurityException

if the app does not have the required permissions to access the surface

androidx.car.app.HostException

if the remote call fails

showAlert

Added in 1.2.0
@RequiresCarApi(value = 5)
fun showAlert(alert: Alert): Unit

Shows an alert on the car screen.

Alerts with the same id, in the scope of the application, are considered equal. Even if their content differ.

Posting an alert while another alert is displayed would dismiss the old alert and replace it with the new one.

Only navigation templates support alerts. Triggering an alert while showing a non-supported template results in the cancellation of the alert.

Parameters
alert: Alert

the alert to show

Throws
androidx.car.app.HostException

if the remote call fails

java.lang.NullPointerException

if alert is null

showToast

Added in 1.0.0
fun showToast(text: CharSequence, duration: Int): Unit

Shows a toast on the car screen.

Parameters
text: CharSequence

the text to show

duration: Int

how long to display the message

Throws
androidx.car.app.HostException

if the remote call fails

java.lang.NullPointerException

if text is null