# Trip Manager Control

### Enable Trip Detection and Recording

Trip detection and recording does not happen until you explicitly enable it at least once. Use the `enableTripManager` method to enable trip detection, recording, and trip file upload. Use the `disableTripManager` method to stop, such as when the user logs out.

Note that once `ImsTripManager` is enabled, it remains enabled even when the application restarts or the phone reboots. You only need to explicitly re-enable it if you previously disabled it.

When the trip manager is enabled it performs a comprehensive status check. Since some of the configuration is done in background, no status is returned from the `enableTripManager` method. Instead, you should monitor the `status` value in the trip status listener callback in case a user-addressable problem is detected. Typical problems are missing permissions (e.g. background location) or phone state (e.g. Bluetooth turned off).

```kotlin
// Enable Trip Detection using the current user's Identity
ImsTripManager.enableTripManager(context, currentIdentity);
```

Also, `disableTripManager` method is called, the SDK stops detecting any trip. This method has a boolean for deleting trip files. When `true` is passed in the method, the SDK will delete any trip files that are not uploaded yet, such as when user logs out.

```kotlin
//Disable Trip Detection but do not delete pending trip files
ImsTripManager.disableTripManager(context, deleteTripFiles)
```

Note that trip detection will only happen automatically if you specify at least one validator.

### Programmatically Starting and Stopping Trips

The trip detection manager must be enabled before the trip recorder can be started or stopped programmatically (see previous section).

```kotlin
    ImsTripManager.startTrip(context, 0, null)
    // ...
    ImsTripManager.stopTrip(context, 0, null)
```

The start command has no effect if the recorder is already started (or if trip detection is disabled), and the stop command has no effect if the recorder's not already running.

* If you have specified no validator (`TripValidator.PHONE` and/or `TripValidator.DEVICE`), then, once started, the trip recorder will continue recording indefinitely until you issue the stop command.
* If you have specified at least one validator, trip recording will stop automatically using the validator, or when you issue the stop command, whichever comes first.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sdk.ims.tech/readme/android/using-the-sdk/trip-detection-and-recording/trip-manager-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
