# SessionController

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

*** ** * ** ***

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

<br />

```
class SessionController
```

<br />

*** ** * ** ***

[SessionController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController)provides API that allows testing of a[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session).

This controller allows:

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

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SessionController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController#SessionController(androidx.car.app.Session,androidx.car.app.testing.TestCarContext,android.content.Intent))`(` ` session: `[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session)`,` ` context: `[TestCarContext](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestCarContext)`,` ` intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html) `)` Creates a[SessionController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController)to control the provided[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session). |

|                                              ### Public functions                                              |
|----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session)                             | [getSession](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController#getSession())`()` Returns the[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session)that is being controlled.                                                                                                                                                            |
| [SessionController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController) | [moveToState](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController#moveToState(androidx.lifecycle.Lifecycle.State))`(state: `[Lifecycle.State](https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State)`)` Moves the[Session](https://developer.android.com/reference/kotlin/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)  

```
SessionController(
    session: Session,
    context: TestCarContext,
    intent: Intent
)
```

Creates a[SessionController](https://developer.android.com/reference/kotlin/androidx/car/app/testing/SessionController)to control the provided[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session).  

|                                                     Parameters                                                      |
|---------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `session: `[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session)                       | the[Session](https://developer.android.com/reference/kotlin/androidx/car/app/Session)to control                                                                                                                                         |
| `context: `[TestCarContext](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestCarContext) | the[TestCarContext](https://developer.android.com/reference/kotlin/androidx/car/app/testing/TestCarContext)that the`session`should use.                                                                                                 |
| `intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)                             | the[Intent](https://developer.android.com/reference/android/content/Intent.html)that the`session`should start with during the[CREATED](https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#CREATED)state. |

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

## Public functions

### getSession

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

```
fun getSession(): Session
```

Returns the[Session](https://developer.android.com/reference/kotlin/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)  

```
fun moveToState(state: Lifecycle.State): SessionController
```

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

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

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