# TestAppManager

# TestAppManager

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/testing/TestAppManager "View this page in Java")

<br />

```
class TestAppManager : AppManager
```

<br />

|---|---|-----------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                                      |||
| ↳ | [androidx.car.app.AppManager](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager)                            ||
|   | ↳ | [androidx.car.app.testing.TestAppManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager) |

*** ** * ** ***

The[AppManager](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager)that is used for testing.

This class will track the following usages of the[AppManager](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager)throughout your test:

- All[SurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback)s set via calling[setSurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback)).
- The[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)s returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate())due to invalidate calls via[invalidate](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#invalidate()).
- All toasts shown via calling[showToast](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showToast(java.lang.CharSequence,int)).

## Summary

|                                                                                                                                                                                                                         ### Public functions                                                                                                                                                                                                                         |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback)`?`                                                                                                                                                                                                                                                                                                                                                                | [getSurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#getSurfaceCallback())`()` Returns the callback set via[setSurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback)), or`null`if not set.                                                                                                                                                                                                                                                                                 |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[Pair](https://developer.android.com/reference/android/util/Pair.html)`<`[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)`!, `[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)`!>!>` | [getTemplatesReturned](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#getTemplatesReturned())`()` Returns all the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)s returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate())due to a call to[invalidate](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#invalidate()), and the respective[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)instance that returned it. |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`!>`                                                                                                                                                             | [getToastsShown](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#getToastsShown())`()` Returns all the toasts shown via[showToast](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showToast(java.lang.CharSequence,int)).                                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                                                                                                                                                                        | [reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#reset())`()` Resets the values tracked by this[TestAppManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager)and all[ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController)s.                                                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                                                                                                                                                                        | [setSurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback))`(surfaceCallback: `[SurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/SurfaceCallback)`?)` Sets the[SurfaceCallback](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.                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                                                                                                                                                                                                        | [showToast](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#showToast(java.lang.CharSequence,int))`(text: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`, duration: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Shows a toast on the car screen.                                                                                                                                                                                                                                                |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.car.app.AppManager](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager) |-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[RequiresCarApi](https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi)`(value = 5)` [dismissAlert](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#dismissAlert(int))`(alertId: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Dismisses the alert with the given`id`.                     | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [invalidate](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#invalidate())`()` Requests the current template to be invalidated, which eventually triggers a call to[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate())to get the new template to display.                                                        | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[RequiresCarApi](https://developer.android.com/reference/kotlin/androidx/car/app/annotations/RequiresCarApi)`(value = 5)` [showAlert](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showAlert(androidx.car.app.model.Alert))`(alert: `[Alert](https://developer.android.com/reference/kotlin/androidx/car/app/model/Alert)`)` Shows an alert on the car screen. | |

## Public functions

### getSurfaceCallback

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

```
fun getSurfaceCallback(): SurfaceCallback?
```

Returns the callback set via[setSurfaceCallback](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback)), or`null`if not set.  

### getTemplatesReturned

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

```
fun getTemplatesReturned(): (Mutable)List<Pair<Screen!, Template!>!>
```

Returns all the[Template](https://developer.android.com/reference/kotlin/androidx/car/app/model/Template)s returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate())due to a call to[invalidate](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#invalidate()), and the respective[Screen](https://developer.android.com/reference/kotlin/androidx/car/app/Screen)instance that returned it. The results are stored in the order in which they were returned from[onGetTemplate](https://developer.android.com/reference/kotlin/androidx/car/app/Screen#onGetTemplate()), where the first template in the list, is the first template returned.

The results will be stored until[reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#reset())is called.  

### getToastsShown

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

```
fun getToastsShown(): (Mutable)List<CharSequence!>
```

Returns all the toasts shown via[showToast](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showToast(java.lang.CharSequence,int)).

The toasts are stored in the order in which they are sent via[showToast](https://developer.android.com/reference/kotlin/androidx/car/app/AppManager#showToast(java.lang.CharSequence,int)), where the first toast in the list is the first toast that was sent.

The toasts will be stored until[reset](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager#reset())is called.  

### reset

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

```
fun reset(): Unit
```

Resets the values tracked by this[TestAppManager](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestAppManager)and all[ScreenController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/ScreenController)s.  

### setSurfaceCallback

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

Sets the[SurfaceCallback](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[Surface](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[getMainLooper](https://developer.android.com/reference/android/os/Looper.html#getMainLooper()).  

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

### showToast

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

Shows a toast on the car screen.  

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

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