# SessionController

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/SessionController.java+class:androidx.car.app.testing.SessionController) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***


```
public class SessionController
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/androidx/car/app/testing/SessionController` provides API that allows testing of a `https://developer.android.com/reference/androidx/car/app/Session`.

This controller allows:

- Injecting a `https://developer.android.com/reference/androidx/car/app/testing/TestCarContext` into the `https://developer.android.com/reference/androidx/car/app/Session` instance, which provides access to the test managers and other testing functionalities.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/car/app/testing/SessionController#SessionController(androidx.car.app.Session,androidx.car.app.testing.TestCarContext,android.content.Intent)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Session session, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/testing/TestCarContext context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent )` Creates a `https://developer.android.com/reference/androidx/car/app/testing/SessionController` to control the provided `https://developer.android.com/reference/androidx/car/app/Session`. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Session` | `https://developer.android.com/reference/androidx/car/app/testing/SessionController#getSession()()` Returns the `https://developer.android.com/reference/androidx/car/app/Session` that is being controlled. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/testing/SessionController` | `https://developer.android.com/reference/androidx/car/app/testing/SessionController#moveToState(androidx.lifecycle.Lifecycle.State)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State state)` Moves the `https://developer.android.com/reference/androidx/car/app/Session` being controlled to the input `state`. |

## Public constructors

### SessionController

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

```
public SessionController(
    @NonNull Session session,
    @NonNull TestCarContext context,
    @NonNull Intent intent
)
```

Creates a `https://developer.android.com/reference/androidx/car/app/testing/SessionController` to control the provided `https://developer.android.com/reference/androidx/car/app/Session`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/Session session` | the `https://developer.android.com/reference/androidx/car/app/Session` to control |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/testing/TestCarContext context` | the `https://developer.android.com/reference/androidx/car/app/testing/TestCarContext` that the `session` should use. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent` | the `https://developer.android.com/reference/android/content/Intent.html` that the `session` should start with during the `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#CREATED` state. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `session` or `context` is `null` |

## Public methods

### getSession

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

```
public @NonNull Session getSession()
```

Returns the `https://developer.android.com/reference/androidx/car/app/Session` that is being controlled.

### moveToState

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

```
public @NonNull SessionController moveToState(@NonNull Lifecycle.State state)
```

Moves the `https://developer.android.com/reference/androidx/car/app/Session` being controlled to the input `state`.

Note that `https://developer.android.com/reference/androidx/lifecycle/Lifecycle.State#DESTROYED` is a terminal state, and you cannot move to any other state after the `https://developer.android.com/reference/androidx/car/app/Session` reaches that state.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/Session#getLifecycle()` |   |