# Trips

> **Note (legacy): A newer version of the Navigation SDK is available**
> 
> This page uses v1.6.2 of the Mapbox Navigation SDK. A newer version of the SDK is available. Learn about the latest version, v2.22.2, in the [Navigation SDK documentation](https://docs.mapbox.com/android/navigation/v2/guides/get-started/initialization/).

The Mapbox Navigation SDK's internal logic runs various calculations, no matter whether it's for turn-by-turn navigation or [free-drive mode](https://docs.mapbox.com/android/legacy/navigation/guides/free-drive/). It manages, filters, and enhances location updates. It computes precise route progress data when navigating. It has many observers and you can receive callbacks that deliver various types of information.

There are times when you might want to plainly know when this logic has started or stopped. When it changes, perhaps you'll make `Location` listening updates, change an Android-system `View'`s visibility, or move [the `MapboxMap`'s camera](https://docs.mapbox.com/android/maps/guides/camera-and-animation/camera/).

This page explains how you can be notified of the start or stop state so that you can make the changes that you want.

## Managing the session

To take advantage of the Navigation SDK's observers and logic, you need to [request the location permissions](https://docs.mapbox.com/android/core/guides/#permissionsmanager) and start the trip session:

```kotlin
mapboxNavigation.startTripSession()
```

When started, the session will create and run a [Foreground Android Service](https://developer.android.com/guide/components/services#Types-of-services), ensuring a stable stream of raw location updates to process, even when the app is in the background.

To pause the stream of navigation events and stop the Foreground Service, call:

```kotlin
mapboxNavigation.stopTripSession()
```

## Trip session events

While the session is started and actively processing raw location updates, it returns the computed data using multiple observers:

-   [Location updates](https://docs.mapbox.com/android/legacy/navigation/guides/device-location/)
-   [Route progress](https://docs.mapbox.com/android/legacy/navigation/guides/route-progress/)
-   [Off-route detection](https://docs.mapbox.com/android/legacy/navigation/guides/off-route/)
-   [Faster route detection](https://docs.mapbox.com/android/legacy/navigation/guides/faster-route/)

## Observe `TripSessionState`

The `TripSessionStateObserver` observer interface provides a `TripSessionState` object whenever the state has changed.

The Navigation SDK's `TripSessionState` enum class provides the two possible states:

-   `STARTED` – State when the session is active. An active session runs a foreground service. `Location` updates are continually requested and returned to the Navigation SDK.
-   `STOPPED` – State when the session is inactive.

To observe the session's state, create the interface object:

```kotlin
val tripSessionStateObserver = object : TripSessionStateObserver {

    override fun onSessionStateChanged(tripSessionState: TripSessionState) {

        when (tripSessionState) {

            TripSessionState.STARTED -> {

            }

            TripSessionState.STOPPED -> {

            }
        }
    }
}
```

Register the interface object with your already-instantiated `MapboxNavigation` object:

```kotlin
mapboxNavigation.registerTripSessionStateObserver(tripSessionStateObserver)
```

Don't forget to unregister the `TripSessionStateObserver` interface!:

```kotlin
override fun onStop() {
	super.onStop()
	mapView.onStop()

	mapboxNavigation.unregisterTripSessionStateObserver(tripSessionStateObserver)}
}
```

The unregister call above is automatically done for you if you run `mapboxNavigation.onDestroy()`.