Mesosfer and Cubeacon Initialization in Application onCreate()

Home - Mesosfer and Cubeacon Initialization in Application onCreate()

Andrew Chandra asked 2 years ago

Hi, 
I have a question about the initialization in application onCreate().
I know we initalize it in Application class to make it initialized globally, but I have an issue…I need to use MultiDexApplication and onCreate() is not called when app launch, so Mesosfer and Cubeacon is not initialized.
This is what I have done :

  1. In build gradle add “multiDexEnabled true” and dependencies compile ‘com.android.support:multidex:1.0.1′”
  2. in manifest, in application tag I add android:name=”android.support.multidex.MultiDexApplication”
  3. in my custom MultiDexApplcation class, I use extends MultiDexApplication ie. public class MyApplication extends MultiDexApplication { … }

I also tried to add Multidex.install(this) in attachBaseContext method, but it doesn’t work. I know this is not a Mesosfer specific issue, but if you can help me please answer it.
Thanks

2 Answers
Alann Maulana Staff answered 2 years ago

Hi Andrew,
By using custom application class on your Android project, make sure that you define it in AndroidManifest.xml within application tag. Taking from Mesosfer-Cubeacon project for Android, here is the code :
MesosferApp.java (refers to this link)

public class MesosferApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        // initialize Mesosfer SDK
        Mesosfer.initialize(this, "YOUR-APP-ID-HERE", "YOUR-CLIENT-KEY-HERE");

        // initialize Cubeacon SDK
        Cubeacon.initialize(this);
    }
}

AndroidManifest.xml (refers to this link)

<application
        android:name=".MesosferApp"

FYI, Application#onCreate() called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate()
You can refers to Android Developer page.
 
Regards.

Andrew Chandra answered 2 years ago

Hi,
Thank you for the reply…Actually I found the issue, I should use my custom Application name in the application name’s Manifest instead of “android.support.multidex.MultiDexApplication”
 
So this issue is resolved

Your Answer