Cordova application with MobileFirst start-up flow

In Android Studio, you can review the start-up process of the Cordova app for Android with MobileFirst.

The MobileFirst Cordova plug-in cordova-plugin-mfp has native asynchronous bootstrap sequence. The bootstrap sequence must be completed before the Cordova application loads the application's main html file.

Adding the cordova-plugin-mfp plug-in to a Cordova application instruments the application's AndroidManifest file and the MainActivity extending the CordovaActivity native code to perform the MobileFirst initialization. MobileFirst can also be used in Cordova applications configured with the Crosswalk WebView.

The application native code instrumentation consists of:

Implementing WLInitWebFrameworkListener and creating the WL object

The MainActivity.java file creates the initial MainActivity class extending the CordovaActivity class. The WLInitWebFrameworkListener receives notification when the MobileFirst framework is initialized.

public class MainActivity extends CordovaActivity implements WLInitWebFrameworkListener {

The MFPApplication class is called from within onCreate and creates a MobileFirst client instance (com.worklight.androidgap.api.WL) that is used throughout the app. The onCreate method initializes the WebView framework.

@Overridepublic void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

if (!((MFPApplication)this.getApplication()).hasCordovaSplashscreen()) {
           WL.getInstance().showSplashScreen(this);
       } 
   init();
   WL.getInstance().initializeWebFramework(getApplicationContext(), this);
}

The MFPApplication class has two functions:

Loading the WebView

The cordova-plugin-mfp plug-in adds an activity to the AndroidManifest.xml file that is required for initializing the Crosswalks WebView:

<activity android:name="com.ibm.MFPLoadUrlActivity" />.

This activity is used to ensure the asynchronous initialization of the Crosswalk WebView as follows:

After the MobileFirst framework is initialized and ready to load in the WebView, the onInitWebFrameworkComplete connects to the URL if WLInitWebFrameworkResult succeeds.

public void onInitWebFrameworkComplete(WLInitWebFrameworkResult result){
if (result.getStatusCode() == WLInitWebFrameworkResult.SUCCESS) {
super.loadUrl(WL.getInstance().getMainHtmlFilePath());
   } else {
      handleWebFrameworkInitFailure(result);
   }
}

For details on the WebView development see Cordova WebView.