# Automatic Detections with Forced Trips

While in [automatic detection mode](https://github.com/sentiance/v4-docs/blob/main/important-topics/sdk/appendix/controlled-detections/broken-reference/README.md), the SDK can be forced to start a trip. Doing so will prevent the SDK from detecting stationary moments and force it to continue collecting trip data until the trip is explicitly stopped.

Once the forced trip is stopped, the SDK will resume automatic detections.

## Starting a Trip

You can start a trip as follows:

{% tabs %}
{% tab title="iOS" %}

```swift
Sentiance.shared.startTrip(metadata: metadata, transportModeHint: hint) { result, error in
}
```

The `metadata` is an `NSDictionary` representing a map of string to string types. You can use it to attach any piece of information to this trip. The `transportModeHint` is a hint you can give the SDK about the type of transport the trip is (e.g. car, bicycle, etc.).

In case starting a trip fails, you can check the error to determine the reason.
{% endtab %}

{% tab title="Android" %}

```kotlin
sentiance.startTrip(metadata, transportModeHint)
    .addOnSuccessListener { startTripResult -> 
        // The trip was successfully started.
    }
    .addOnFailureListener { startTripError ->
        // Something prevented the trip to start.
        // Check the status object for more details.
    }
```

The `metadata` is a map of string to string types. You can use it to attach any piece of information to this trip. The `transportModeHint` is a hint of type [`TransportMode`](/important-topics/sdk/api-reference/android/trip/transportmode.md) you can give the SDK about the type of transport the trip is (e.g. car, bicycle, etc.).

You can add an [OnSuccessListener](/important-topics/sdk/api-reference/android/pendingoperation/onsuccesslistener.md) and [`OnFailureListener`](/important-topics/sdk/api-reference/android/pendingoperation/onfailurelistener.md) to the returned [`PendingOperation`](/important-topics/sdk/api-reference/android/pendingoperation.md), you will be notified when a trip is successfully started. If it fails, you can check the [`StartTripError`](/important-topics/sdk/api-reference/android/starttriperror.md) object to determine the reason.
{% endtab %}
{% endtabs %}

## Stopping a Trip

To stop a trip that you've started, call `stopTrip` as follows:

{% tabs %}
{% tab title="iOS" %}

```swift
Sentiance.shared.stopTrip { result, error in
}
```

If stopping the trip fails, you can check the error to determine why. To check if a trip is ongoing before calling `stopTrip`, see [this](https://github.com/sentiance/v4-docs/blob/main/important-topics/sdk/appendix/controlled-detections/broken-reference/README.md) guide.
{% endtab %}

{% tab title="Android" %}

```kotlin
sentiance.stopTrip()
    .addOnSuccessListener { stopTripResult -> }
    .addOnFailureListener { stopTripError -> }
```

You can add an [OnSuccessListener](/important-topics/sdk/api-reference/android/pendingoperation/onsuccesslistener.md) and [`OnFailureListener`](/important-topics/sdk/api-reference/android/pendingoperation/onfailurelistener.md) to the returned [`PendingOperation`](/important-topics/sdk/api-reference/android/pendingoperation.md), you will be notified when a trip is successfully started. If it fails, you can check the [`StopTripError`](/important-topics/sdk/api-reference/android/stoptriperror.md) object to determine the reason.

To check if a trip is ongoing before calling [`stopTrip()`](/important-topics/sdk/api-reference/android/sentiance.md#stoptrip), see [this](https://github.com/sentiance/v4-docs/blob/main/important-topics/sdk/appendix/controlled-detections/broken-reference/README.md) guide.
{% endtab %}
{% endtabs %}


---

# 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://docs.sentiance.com/important-topics/sdk/appendix/controlled-detections/automatic-detections-with-forced-trips.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.
