> For the complete documentation index, see [llms.txt](https://docs.movesdk.com/move-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.movesdk.com/move-platform/sdk/api-interface/android/initialization.md).

# Initialization

## Init

The Android MOVE SDK must be initialized by adding MoveSdk.init() at the first line in your Android Application class (onCreate). This instance can then be used to control MOVE SDK services.

After the MOVE SDK has been initialized you also want to add notifications, listeners or activate additional features.

Also you have to configure the MOVE SDK before you are able to call .setup(...).

```kotlin
// your application class

override fun onCreate() {
   // init the MOVE SDK
   val moveSdk = MoveSdk.init(this)   
   
   super.onCreate()

   // Example of adding some notifications, register listener
   // and activate MOVE SDK features.
   moveSdk.apply {
     recognitionNotification(recognitionNotification)
     tripNotification(drivingNotification)
     sdkStateListener(sdkStateListener)
     tripStateListener(tripStateListener)
     authStateUpdateListener(authStateListener)
     initializationListener(initListener)
     setServiceErrorListener(errorListener)
     setServiceWarningListener(warningListener)
     initiateAssistanceCall(assistanceListener)
     deviceDiscoveryListener(deviceDiscoveryListener)
     consoleLogging(true)
   }
   
   // ... continue with Config ...
}
```

{% hint style="info" %}
**Note:** `MoveSdk.get()` returns `null` if `MoveSdk.init()` has not been called yet. Always ensure `MoveSdk.init()` is called first in `Application.onCreate()` before accessing the SDK instance.
{% endhint %}

By clicking the links below you can find further information about the usage.

* [recognitionNotification](#dolphinsdk.builderv1.1-recognitionnotificationrecognitionnotifications)
* [tripNotification](#trip-notifications)
* [sdkStateListener](#dolphinsdk.builderv1.1-sdkstatelistenersdkstatelistener)
* [tripStateListener](#trip-state-listener)
* [authStateUpdateListener](#dolphinsdk.builderv1.1-initializationinitializationlistener-1)
* [initializationListener](#dolphinsdk.builderv1.1-initializationinitializationlistener)

Used Services in the example above and [more](/move-platform/sdk/api-interface/android/services.md):

* [setServiceErrorListener](/move-platform/sdk/api-interface/android/services.md#set-service-error-listener)
* [setServiceWarningListener](/move-platform/sdk/api-interface/android/services.md#set-service-warning-listener)
* [initiateAssistanceCall](/move-platform/sdk/api-interface/android/services.md#initiate-assistance-call)
* [consoleLogging](/move-platform/sdk/api-interface/android/services.md#console-logging)
* [deviceDiscoveryListener](/move-platform/sdk/api-interface/android/services.md#set-device-discovery-listener)

## Config <a href="#config" id="config"></a>

Whenever you are ready to start the Move SDK, setup() needs to be called with a proper configuration. The following code sample demonstrates a common configuration with driving, walking, cycling, automatic impact detection and assistance call.

```kotlin
   // ... Init ...
   
   // Example of a configuration of the MOVE SDK
    val moveConfig = MoveConfig(
        moveDetectionServices = listOf(
            MoveDetectionService.Driving(
                drivingServices = listOf(
                    DrivingService.DrivingBehaviour,
                    DrivingService.DistractionFreeDriving,
                    DrivingService.DeviceDiscovery,
                )
            ),
            MoveDetectionService.Walking(),
            MoveDetectionService.Cycling,
            MoveDetectionService.AutomaticImpactDetection,
            MoveDetectionService.AssistanceCall,
        )
    )
   // ... continue with Setup ...
```

## Setup

{% hint style="warning" %}
It is recommended to set up notifications before calling the setup() method.
{% endhint %}

{% hint style="warning" %}
It is recommended that .setup(...) is called **ONLY ONCE!**

If .shutdown() was called before then .setup(...) must be redone.
{% endhint %}

### With MoveAuth

{% hint style="warning" %}
Deprecated in the future. The new approach is by using an authCode. see [Setup with authCode](#with-authcode)
{% endhint %}

The data for the MoveAuth object must be fetched using the given project’s API Key (see [MOVE Backend - Example request](/move-platform/backend/example-requests.md#create-a-new-user)).

```kotlin
.setup(
    auth: MoveAuth, 
    config: MoveConfig,
    start: Boolean?,
    options: MoveOptions?
)
```

<table data-header-hidden><thead><tr><th width="263.3333333333333">Parameter</th><th width="220"></th><th>Description</th></tr></thead><tbody><tr><td>auth</td><td><a href="/pages/-MaaWZTWSWCAh0OtxoEQ">MoveAuth</a></td><td>The user's Auth object. (see <a href="/pages/qtj1PULV3mtHMgL0LMYm#create-a-new-user">MOVE Backend - Create a new user</a>) </td></tr><tr><td>config</td><td><a href="/pages/-MaaWY9OqkZbnWjtjqNT">MoveConfig</a></td><td>The move configuration</td></tr><tr><td>start</td><td>Boolean</td><td>optional:<br>Default: <strong>true</strong> ->  <a href="/pages/-MZIkqoqutrz3W0Y7wdZ#start-automatic-detection">startAutomaticDetection()</a> is called automatically<br><br><strong>false</strong> -> you have to call <a href="/pages/-MZIkqoqutrz3W0Y7wdZ#start-automatic-detection">startAutomaticDetection()</a> manually</td></tr><tr><td>options</td><td><a href="/pages/dBe2vpwoFe7N7uC3D0Hr">MoveOptions</a></td><td>optional: added with v2.3.+</td></tr></tbody></table>

{% hint style="warning" %}

### SDK Authentication

Passing the authentication config is **required** for each setup. The host app is also responsible for monitoring the [AuthState](/move-platform/sdk/models/moveauthstate.md) changes.
{% endhint %}

{% hint style="warning" %}
If you want to use startTrip(...) ([**Manual Start Trip**](/move-platform/sdk/api-interface/android/services.md#manual-start-trip)) you have to pass **false** to the parameter **start**.
{% endhint %}

### With authCode

The authCode must be fetched using the userId (see [MOVE Backend - Example request](/move-platform/backend/example-requests.md#create-a-new-user)).

```kotlin
.setup(
    authCode: String, 
    config: MoveConfig,
    start: Boolean?,
    options: MoveOptions?,
    callback: MoveAuthCallback
)
```

<table data-header-hidden><thead><tr><th width="263.3333333333333">Parameter</th><th width="220"></th><th>Description</th></tr></thead><tbody><tr><td>authCode</td><td>String</td><td>The authCode received from the backend. (see <a href="/pages/qtj1PULV3mtHMgL0LMYm#create-a-new-user">MOVE Backend - Create a new user</a>) </td></tr><tr><td>config</td><td><a href="/pages/-MaaWY9OqkZbnWjtjqNT">MoveConfig</a></td><td>The move configuration</td></tr><tr><td>start</td><td>Boolean</td><td>optional:<br>Default: <strong>true</strong> ->  <a href="/pages/-MZIkqoqutrz3W0Y7wdZ#start-automatic-detection">startAutomaticDetection()</a> is called automatically<br><br><strong>false</strong> -> you have to call <a href="/pages/-MZIkqoqutrz3W0Y7wdZ#start-automatic-detection">startAutomaticDetection()</a> manually</td></tr><tr><td>options</td><td><a href="/pages/dBe2vpwoFe7N7uC3D0Hr">MoveOptions</a></td><td></td></tr><tr><td>callback</td><td>MoveAuthCallback</td><td>This listener will report the success or failure during the internal MOVE SDK authentication process. (see <a href="/pages/nbktxZFZnLu565SRQeVc">MoveAuthResult</a>)</td></tr></tbody></table>

#### Example of implementing the MoveAuthCallback:

```kotlin
private val moveAuthCallback = object : MoveSdk.MoveAuthCallback {
    override fun onResult(result: MoveAuthResult) {
        when (result.status) {
            AuthSetupStatus.SUCCESS -> {
                // Do something if the result is SUCCESS.
            }
            AuthSetupStatus.INVALID_CODE -> {
                // Do something if the result is INVALID_CODE.
            }
            AuthSetupStatus.NETWORK_ERROR -> {
                // Do something if the result is NETWORK_ERROR.
            }
        }
    }
}
```

## Listeners

### Initialization listener <a href="#dolphinsdk.builderv1.1-initializationinitializationlistener" id="dolphinsdk.builderv1.1-initializationinitializationlistener"></a>

Block that gets invoked on initialization completion with error. On error, [MoveConfigurationError](/move-platform/sdk/models/moveconfigurationerror.md#android) is returned. On success, the [MoveSdkState](/move-platform/sdk/models/movesdkstate.md) will change accordingly.

```kotlin
fun initializationListener(callback: InitializeListener)
```

| Parameter |                                                                                            | Description                                                                                                                                                            |
| --------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| listener  | [InitializeListener](/move-platform/sdk/models/listeners-callbacks.md#initialize-listener) | <p>Block that gets invoked on initialization completion with error. On error, </p><p><a href="/pages/-MaaWYf8OHiAF4kfCW1V">MoveConfigurationError</a> is returned.</p> |

### Auth state update listener <a href="#dolphinsdk.builderv1.1-initializationinitializationlistener" id="dolphinsdk.builderv1.1-initializationinitializationlistener"></a>

Provide a block to be invoked every time [MoveAuthState](/move-platform/sdk/models/moveauthstate.md) changes.

```kotlin
fun authStateUpdateListener(callback: AuthStateUpdateListener)
```

| **Callback**            |                                                                                                            |
| ----------------------- | ---------------------------------------------------------------------------------------------------------- |
| AuthStateUpdateListener | Block that gets invoked every time [MoveAuthState](/move-platform/sdk/models/moveauthstate.md) is updated. |

{% hint style="warning" %}

### Authentication

Check [Authentication updates](/move-platform/sdk/models/moveauthstate.md#authentication-updates-and-expiry) for more details about authentication expiry and renewal.
{% endhint %}

### MOVE SDK State listener <a href="#dolphinsdk.builderv1.1-sdkstatelistenersdkstatelistener" id="dolphinsdk.builderv1.1-sdkstatelistenersdkstatelistener"></a>

&#x20;Provide a block to be invoked every time[ MoveSdkState](/move-platform/sdk/models/movesdkstate.md) changes.

{% hint style="warning" %}
The host app is expected to be monitoring [MoveSdkState](/move-platform/sdk/models/movesdkstate.md) changes so it can start the SDK services when [MoveSdkState](/move-platform/sdk/models/movesdkstate.md) is`.ready`or handle errors if occurred.
{% endhint %}

```kotlin
fun sdkStateListener(listener: StateListener)
```

| Parameter |                                                                                          | Description                                                                                       |
| --------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| listener  | [StateListener](/move-platform/sdk/models/listeners-callbacks.md#movesdk-state-listener) | Block gets called whenever the [MoveSdkState](/move-platform/sdk/models/movesdkstate.md) changes. |

### Trip state listener

```kotlin
fun tripStateListener(listener: TripStateListener)
```

| Parameter |                                                                                           | Description                                                                                                                                                                                                                                                                                 |
| --------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| listener  | [TripStateListener](/move-platform/sdk/models/listeners-callbacks.md#trip-state-listener) | A listener where [`onTripStateChanged`](https://docs.movesdk.com/move-platform/sdk/api-interface/android/pages/-MZIfp4AHvpUSOaycA60#DolphinSdk.Builderv1.1-tripstatelistenerTripstatelistener) gets called whenever the [MoveTripState](/move-platform/sdk/models/movetripstate.md) changes |

### Trip notifications

Passes a notification builder which is used to create a notification reaching places and walking paths. For more information on that please check[ notification management](/move-platform/sdk/appendix/android/notification-management.md).

```kotlin
fun tripNotification(notification: Notification)
fun tripNotification(notification: NotificationCompat.Builder)
```

| Parameter                  | Description                                                                     |
| -------------------------- | ------------------------------------------------------------------------------- |
| NotificationCompat.Builder | The notification builder to build the notification `package androidx.core.app`. |
| Notification               | A class that represents how a persistent notification `package android.app`.    |

### Recognition notifications <a href="#dolphinsdk.builderv1.1-recognitionnotificationrecognitionnotifications" id="dolphinsdk.builderv1.1-recognitionnotificationrecognitionnotifications"></a>

Passes a notification  builder which is used to create notification while detecting activities, trips and more. For more information on that, please check[ notification management](/move-platform/sdk/appendix/android/notification-management.md).

```kotlin
fun recognitionNotification(notification: Notification)
fun recognitionNotification(notification: NotificationCompat.Builder)
```

| Parameter                  | Description                                                                     |
| -------------------------- | ------------------------------------------------------------------------------- |
| NotificationCompat.Builder | The notification builder to build the notification `package androidx.core.app`. |
| Notification               | A class that represents how a persistent notification `package android.app`.    |

### Trip Metadata <a href="#dolphinsdk.builderv1.2-metadatametadata" id="dolphinsdk.builderv1.2-metadatametadata"></a>

Host apps can use this API to add any app-level information (for ex. bluetooth beacon detected, foreground/background time, etc) to append to a trip as metadata. This metadata will be forwarded back along with the trip when fetched by the client-server, so the host app can utilize it in its app. Note: The MOVE SDK will not use this metadata element in any way, it is just passed through to the project.

The block provides the trip's start and stop times. Make sure to only include metadata events that are collected inside the given start and end periods.

```kotlin
fun metadataProvider(provider: TripMetadataProvider)
```

| Parameter                                                                           | Description                                                                                                          |
| ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [provider](/move-platform/sdk/models/listeners-callbacks.md#trip-metadata-provider) | Callback to provide a bundle of key-value pairs to a trip. The trip is represented with a given start and stop time. |

## Initialization

Tries to initialize the MOVE SDK. You can only have one initialized MOVE SDK at a time. If you have a MOVE SDK instance already, consider calling [`shutdown`](/move-platform/sdk/api-interface/android/services.md#shutdown-sdk)before.\
The initialization process is asynchronous and the host app is expected to register a [MoveSdkState](/move-platform/sdk/models/movesdkstate.md) [`listener`](https://docs.movesdk.com/move-platform/sdk/api-interface/android/pages/-MZIfp4AHvpUSOaycA60#DolphinSdk.Builderv1.1-sdkstatelistenerSdkstatelistener) to monitor successful initialization and start services when [MoveSdkState](/move-platform/sdk/models/movesdkstate.md) transits to`READY` . The host app should also monitor [`initialization listener`](https://docs.movesdk.com/move-platform/sdk/api-interface/android/pages/-MZIfp4AHvpUSOaycA60#DolphinSdk.Builderv1.1-initializationInitializationlistener) to handle potential [MoveConfigurationError](/move-platform/sdk/models/moveconfigurationerror.md).

{% hint style="warning" %}

### Application Context

Make sure to pass the application context
{% endhint %}

| Parameter | Description               |
| --------- | ------------------------- |
| context   | Main application context. |

```kotlin
fun init(context: Context): MoveSdk
```

| **Return** |                             |
| ---------- | --------------------------- |
| MoveSdk    | The instance of the MoveSdk |

{% hint style="info" %}
If you have already successfull initialized the MOVE SDK once, try to initialize the MOVE SDK next time in your application in [onCreate](https://developer.android.com/reference/android/app/Application#onCreate\(\)). This ensures that the MOVE SDK can do its work whenever the application is restarted after termination.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.movesdk.com/move-platform/sdk/api-interface/android/initialization.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
