# Initialization

The MOVE SDK must be initialized natively. For the first init, the SDK expects to be setup after user onboarding using Flutter. In this case, Flutter passes the required auth code or [MoveAuth](/move-platform/sdk/models/moveauth.md), and [MoveConfig](/move-platform/sdk/models/moveconfig.md) objects.

In all future inits, the SDK expects to be initialized natively at app start points (MainApplication for Android). This is to guarantee that the MOVE SDK is set up and active before the limited time provided by the OS in background wakeups is consumed.&#x20;

The native init will re-use the last authentication and configs objects passed to the SDK from the Flutter initialization.

```dart
import 'package:movesdk/movesdk.dart';
```

## Setup MOVE SDK

### With MoveAuth

To setup the MOVE SDK with a registered user you have to provide [**MoveAuth**](https://docs.movesdk.com/move-platform/sdk/models/moveauth#react-native), [**MoveConfig**](https://docs.movesdk.com/move-platform/sdk/models/moveconfig#react-native):

```dart
Future<void> setup(
        MoveAuth auth,
        MoveConfig moveConfig,
        {MoveOptions? options}
)
```

<table data-header-hidden><thead><tr><th width="196.66666666666669"></th><th></th></tr></thead><tbody><tr><td><strong>Parameters</strong></td><td></td></tr><tr><td><code>auth</code></td><td><a href="/pages/-MaaWZTWSWCAh0OtxoEQ#flutter">MoveAuth</a> object to authenticate the user. See <a href="/pages/qtj1PULV3mtHMgL0LMYm#create-a-new-user">Move Backend</a> section for acquiring credentials.</td></tr><tr><td><code>moveConfig</code></td><td><a href="/pages/-MaaWY9OqkZbnWjtjqNT#flutter">MoveConfig</a> object to setup <a href="/pages/JKL0LkFl27alD5tu3UP0#detection-services">services</a>.</td></tr><tr><td><code>options</code></td><td>Optional <a href="/pages/dBe2vpwoFe7N7uC3D0Hr#flutter">MoveOptions</a> object</td></tr></tbody></table>

{% hint style="warning" %}
Will be remove in future versions, use `setupWithCode(...)` instead.
{% endhint %}

### **With authCode**

Alternative to the approach with the MoveAuth you can setup the MOVE SDK with an authentication string. This **authCode** must be fetched from the backend using the userId (see [MOVE Backend - Example request](/move-platform/backend/example-requests.md#create-a-new-user-authcode)).

```dart
Future<MoveAuthResult> setupWithCode(
        String authCode,
        MoveConfig moveConfig,
        {MoveOptions? options}
)
```

<table data-header-hidden><thead><tr><th width="214.66666666666669"></th><th></th></tr></thead><tbody><tr><td><strong>Parameters</strong></td><td></td></tr><tr><td><code>authCode</code></td><td>authCode string to authenticate the user. See <a href="/pages/qtj1PULV3mtHMgL0LMYm#create-a-new-user-authcode">Move Backend</a> section for acquiring credentials.</td></tr><tr><td><code>moveConfig</code></td><td><a href="/pages/-MaaWY9OqkZbnWjtjqNT#flutter">MoveConfig</a> object to setup <a href="/pages/JKL0LkFl27alD5tu3UP0#detection-services">services</a>.</td></tr><tr><td><code>options</code></td><td>Optional <a href="/pages/dBe2vpwoFe7N7uC3D0Hr#flutter">MoveOptions</a> object</td></tr><tr><td><strong>Returns</strong></td><td></td></tr><tr><td><a href="/pages/nbktxZFZnLu565SRQeVc#flutter">MoveAuthResult</a></td><td></td></tr></tbody></table>

## **Android**

To initialize the SDK natively, in your MainApplication:

```kotlin
import io.dolphin.move.MoveSdk
...
class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        val sdk = MoveSdk.init(this)
        ...
        // you can use the native class furhter on
        // eg. sdk.allowMockLocations(true)
    }
}
```

{% hint style="info" %}
For iOS the SDK is automatically initialized in the `FlutterPlugin` lifecycle during `didFinishLaunchingWithOptions.`
{% endhint %}

### **Notification**

To use the MoveSdk in the background, it is required to configure the trip or als recognition notification, like shown in the following:

```kotlin
sdk.recognitionNotification(
    NotificationCompat.Builder(this, recognitionChannel)
        .setContentTitle("MOVE SDK")
        .setContentText("Trip detection")
        .setChannelId(recognitionChannel)
)
```

Make sure that you are also creating a notification channel. More information about notifications can be found at [Notification Management](/move-platform/sdk/appendix/android/notification-management.md).

## **Shutdown SDK**

Shutdown SDK shared instance.

Stops SDK services, send the queued user data and de-initializes the SDK. After that is executed,  the [MoveSDKState](/move-platform/sdk/models/movesdkstate.md) will transit to `.uninitialized`.

{% hint style="warning" %}
**Precondition:** SDK must be initialized.
{% endhint %}

```dart
Future<MoveShutdownResult> shutdown({bool force = true})
```

<table data-header-hidden><thead><tr><th width="217.66666666666669"></th><th width="158"></th><th></th></tr></thead><tbody><tr><td><strong>Parameters</strong></td><td><strong>Default</strong></td><td></td></tr><tr><td><code>force</code></td><td><code>true</code></td><td>If true, <code>shutdown</code> executes immediately. Pending Data may be lost.</td></tr><tr><td><strong>Returns</strong></td><td></td><td></td></tr><tr><td><a href="/pages/8oQEwj2v8SSKn1ib9gng#flutter">MoveShutdownResult</a></td><td></td><td></td></tr></tbody></table>

## Configuration services

### Update authentication

Updates SDK [MoveAuth](/move-platform/sdk/models/moveauth.md). The host app was expected to fetch a new [MoveAuth](/move-platform/sdk/models/moveauth.md) using its project API key and pass it to the MoveSDK using the following API:

```dart
@Deprecated('obsolete')
Future<MoveAuthError?> updateAuth(MoveAuth auth)
```

{% hint style="danger" %}
**Deprecated:** Token expiry is no longer a valid auth state forwarded to the app and does not need to be handled.
{% endhint %}

### Update configuration

Updates SDK MoveConfig.

```dart
Future<void> updateConfig(MoveConfig config, {MoveOptions? options})
```

<table><thead><tr><th width="186.4285714285714">Parameters</th><th width="150"> </th></tr></thead><tbody><tr><td><code>config</code></td><td>The new MoveConfig to use.</td></tr><tr><td><code>options</code></td><td><strong>Optional:</strong> The updated MoveOptions to use</td></tr><tr><td><strong>Throws</strong></td><td></td></tr><tr><td><em>uninitialized</em></td><td>The SDK is in <code>uninitialized</code> state.</td></tr></tbody></table>


---

# 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.movesdk.com/move-platform/sdk/api-interface/flutter/initialization.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.
