# 2. Initialization

Initialization sets up internal SDK components to allow the creation of a Sentiance user on the device, and perform detections in the background.

Only a limited set of SDK methods are allowed to be invoked before initializing the SDK.

### 1. Create an Application Class

Initialization must be done in the `onCreate()` method of your `Application` class. If you don't already have a custom application class, first create a new class that extends `Application`.

{% code title="MyApplication.kt" %}

```kotlin
import android.app.Application;

class MyApplication: Application() {
    override fun onCreate() {
        super.onCreate()
    }
}
```

{% endcode %}

Then reference this new class in the application tag of the `AndroidManifest.xml`

```java
<application android:name="com.example.appname.MyApplication">
  <!-- Activities -->
</application>
```

### 2. Initialize the SDK

In the `onCreate()` method of your `Application` class, call `initialize()`.

{% code title="MyApplication.kt" %}

```kotlin
override fun onCreate() {
    super.onCreate()

    val result = Sentiance.getInstance(this).initialize()
    if (result.isSuccessful) {
        Log.d(TAG, "Initialization succeeded");
    }
}
```

{% endcode %}

Initialization will normally succeed, unless an unexpected error or exception is encountered. In case of failure, you can check the reason via the returned result.

```kotlin
if (result.isSuccessful) {
    Log.d(TAG, "Initialization succeeded");
} else {
    Log.e(TAG, "Intialization failed with reason ${result.failureReason!!.name}", result.throwable);
}
```

### 3. Customize the Android Notification (Optional)

When the Sentiance SDK runs in the background, it initiates a foreground service and provides a notification to Android, which is displayed to the user while the service is active.

By customizing the notification you can tailor the appearance and behavior of the notification to match the branding and user experience of your application. This allows you to provide a seamless and consistent experience to your users while the Sentiance SDK operates in the background.

Please note that customizing the notification should be done carefully to ensure that it complies with Android guidelines and user preferences. By doing so, you can enhance the overall user experience and maintain a cohesive presentation of your app and the Sentiance SDK's background functionality.

You can specify the notification that the SDK should use by passing it to the SDK initializer as an option:

```kotlin
val options = SentianceOptions.Builder(context)
    .setNotification(nofitication, id)
    .build()
Sentiance.getInstance(context).initialize(options)
```

If the `id` that you specify here matches the ID of another notification, Android will show only one notification (the last published one). If your app has an ongoing notification of its own, you can do ID sharing to avoid redundant notifications during SDK detections.

Be sure to check our [notification management page](/important-topics/sdk/appendix/android/notification-management.md) for more on the best practices of using service notifications.


---

# 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/a-complete-integration/android-sdk/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.
