Initializing the SDK

After the project is setup, the SDK will have to be initialized before any other API calls to it can be made. To initialized the SmartConnect SDK in your application, proceed as follows:


String SDKKey = "VALID_SDK_KEY";
try {
   SMCCore.initialize( SDKKey , getApplicationContext());
} catch (SMCException e) {
   
}

 

NOTE : Make sure that the Context object that is passed is the Application context and not BaseContext or ActivityContext. This is because the reference to the Context object is held with SmartConnect and passing Activity context will result in a memory leak.

 

Recommendation for initialization

The best way to initialize the SDK is by calling initialize() in theApplicationclass. This will ensure the SDK is always initialized whenever your application is alive. This can be done as follows:


public class MyApplication extends Application {

    private static final String SDK_KEY = "VALID_SDK_KEY";

    @Override
    public void onCreate() {
        super.onCreate();
        try {
            SMCCore.initialize( SDK_KEY , getApplicationContext());
        } catch (SMCException e) {
            
        }
    }
}

NOTE: The application class needs to be explicitly defined in the Manifest file so that Android knows which class to invoke to create the global application state. This can be done by providing the fully-qualified name of this class as the android:name attribute in your AndroidManifest.xml's application tag as follows :

application state. This can be done by providing the fully-qualified name of this class as the android:name attribute in your AndroidManifest.xml's application tag as follows : ...


application android:name=".app.MyApplication">< / application>

NOTE: The Application class can also extend MultiDexApplication based on your MultiDex configuration.

 

Proguard SettingsActivating the SmartConnect SDK