4. Initialization

This document refers to deprecated parts of the platform and has been left intact to help customers with legacy integrations. In order to access the latest platform features and documentation, please go to https://docs.sentiance.com.

Initialization is a very important step; before initialization, none of the methods on the Sentiance SDK interface will work, with the exception of getInstance(), init() and getInitState().

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.

import android.app.Application;
public class MyApplication extends Application {
    @Override
    public void onCreate() {
    }
}

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

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

Call the SDK init Method

In the onCreate() method of your Application class, call init() and pass the SdkConfig you created in the previous step, plus an instance of OnInitCallback to handle the initialization result.

MyApplication.java
@Override
public void onCreate() {
    // Creation of SdkConfig here, see previous step
    
    OnInitCallback initCallback = new OnInitCallback() {
        @Override
        public void onInitSuccess() {
        }
        @Override
        public void onInitFailure(InitIssue issue, @Nullable Throwable th) {
        }
    };
        
    Sentiance.getInstance(this).init(sdkConfig, initCallback);
}

Upon successful initialization, onInitSuccess() will be called. If it fails, onInitFailure() will be called with an appropriate InitIssue.

The init() call must be executed before onCreate() returns. Therefore, you must call it synchronously on the main thread. If you plan to add a remote flag to control the initialization (e.g. Firebase Remote Config), make sure the check is synchronous (e.g. using a cached flag).

See here to understand more about why this is important. An example app demonstrating this can be found on our Github.

To learn more about initialization, see the SDK Initialization section.

Last updated