# 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)

*** ** * ** ***


```
public class TestAppManager extends AppManager
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.car.app.AppManager](https://developer.android.com/reference/androidx/car/app/AppManager) ||
|   | ↳ | [androidx.car.app.testing.TestAppManager](https://developer.android.com/reference/androidx/car/app/testing/TestAppManager) |

*** ** * ** ***

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

This class will track the following usages of the `https://developer.android.com/reference/androidx/car/app/AppManager` throughout your test:

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

## Summary

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/SurfaceCallback` | `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager#getSurfaceCallback()()` Returns the callback set via `https://developer.android.com/reference/androidx/car/app/AppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback)`, or `null` if not set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/android/util/Pair.html<https://developer.android.com/reference/androidx/car/app/Screen, https://developer.android.com/reference/androidx/car/app/model/Template>>` | `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager#getTemplatesReturned()()` Returns all the `https://developer.android.com/reference/androidx/car/app/model/Template`s returned from `https://developer.android.com/reference/androidx/car/app/Screen#onGetTemplate()` due to a call to `https://developer.android.com/reference/androidx/car/app/AppManager#invalidate()`, and the respective `https://developer.android.com/reference/androidx/car/app/Screen` instance that returned it. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/CharSequence.html>` | `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager#getToastsShown()()` Returns all the toasts shown via `https://developer.android.com/reference/androidx/car/app/AppManager#showToast(java.lang.CharSequence,int)`. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager#reset()()` Resets the values tracked by this `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager` and all `https://developer.android.com/reference/androidx/car/app/testing/ScreenController`s. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager#setSurfaceCallback(androidx.car.app.SurfaceCallback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/SurfaceCallback surfaceCallback)` Sets the `https://developer.android.com/reference/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. |
| `void` | `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager#showToast(java.lang.CharSequence,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html text, int duration)` Shows a toast on the car screen. |

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

## Public methods

### getSurfaceCallback

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

```
public @Nullable SurfaceCallback getSurfaceCallback()
```

Returns the callback set via `https://developer.android.com/reference/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)

```
public @NonNull List<Pair<Screen, Template>> getTemplatesReturned()
```

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

The results will be stored until `https://developer.android.com/reference/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)

```
public @NonNull List<CharSequence> getToastsShown()
```

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

The toasts are stored in the order in which they are sent via `https://developer.android.com/reference/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 `https://developer.android.com/reference/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)

```
public void reset()
```

Resets the values tracked by this `https://developer.android.com/reference/androidx/car/app/testing/TestAppManager` and all `https://developer.android.com/reference/androidx/car/app/testing/ScreenController`s.

### setSurfaceCallback

```
public void setSurfaceCallback(@Nullable SurfaceCallback surfaceCallback)
```

Sets the `https://developer.android.com/reference/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/androidx/car/app/HostException` | if the remote call fails |

### showToast

```
public void showToast(@NonNull CharSequence text, int duration)
```

Shows a toast on the car screen.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html text` | the text to show |
| `int duration` | how long to display the message |

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