# AppManager

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/AppManager.java+class:androidx.car.app.AppManager) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
class AppManager : Manager
```

<br />

Known direct subclasses [TestAppManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager` | The `https://developer.android.com/reference/kotlin/androidx/car/app/AppManager` that is used for testing. |

*** ** * ** ***

Manages the communication between the app and the host.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 5) https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#dismissAlert(int)(alertId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Dismisses the alert with the given `id`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#invalidate()()` Requests the current template to be invalidated, which eventually triggers a call to `https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate()` to get the new template to display. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback)(surfaceCallback: https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback?)` Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback` to get changes and updates to the surface on which the app can draw custom content, or `null` to reset the listener. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi(value = 5) https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showAlert(androidx.car.app.model.Alert)(alert: https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert)` Shows an alert on the car screen. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showToast(java.lang.CharSequence,int)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html, duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Shows a toast on the car screen. |

## Public functions

### dismissAlert

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/car-app#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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the `id` of the `alert` that should be dismissed |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the remote call fails |

### invalidate

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun invalidate(): Unit
```

Requests the current template to be invalidated, which eventually triggers a call to `https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate()` to get the new template to display.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the remote call fails |

### setSurfaceCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun setSurfaceCallback(surfaceCallback: SurfaceCallback?): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/car/app/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 `https://developer.android.com/reference/android/view/Surface.html` 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 `https://developer.android.com/reference/android/os/Looper.html#getMainLooper()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if the app does not have the required permissions to access the surface |
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the remote call fails |

### showAlert

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/car-app#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: https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert` | the alert to show |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the remote call fails |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `alert` is `null` |

### showToast

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
fun showToast(text: CharSequence, duration: Int): Unit
```

Shows a toast on the car screen.

| Parameters |
|---|---|
| `text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` | the text to show |
| `duration: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | how long to display the message |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/car/app/HostException` | if the remote call fails |
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `text` is `null` |