All Products
Search
Document Center

Mobile Platform as a Service:Initialize mPaaS

Last Updated:Nov 21, 2023

Before you use the mPaaS framework, you need to initialize the Application object based on whether the Hotpatch feature is enabled. This topic describes the initialization processes in both cases.

When Hotpatch is disabled

When the Hotpatch feature is disabled, you need only to add the following code to the Application object.

@Override
public void onCreate() {
    super.onCreate();
    
    MP.init(
      this,
      MPInitParam.obtain().setCallback(new MPInitParam.MPCallback() {
        @Override
        public void onInit() {
            Log.d("TAG", "mPaaS Init finish");
        }
      })
    );
}
Note
  1. If you integrate Kotlin, you can use mPaaS Kotlin Extension of mPaaS KTX provided by mPaaS.

  2. If you need to continue to use the QuinoxlessFramework initialization method, your calls will not be affected in any way, and no changes to the code or business are required.

Important

Please do not filter the process before using the MP.init method. In addition to the main process, initialization code also needs to be executed in the tools and push child processes.

When Hotpatch is enabled

When the Hotpatch feature is enabled, perform the following steps.

Procedure

  1. In the Application object, re-inherit QuinoxlessApplicationLike and exclude this class from obfuscation. In the following code, the MyApplication object is used as an example.

     @Keep
     public class MyApplication extends QuinoxlessApplicationLike implements Application.ActivityLifecycleCallbacks {
    
      private static final String TAG = "MyApplication";
    
      @Override
      protected void attachBaseContext(Context base) {
          super.attachBaseContext(base);
    
          Log.i(TAG, "attacheBaseContext");
    
      }
    
      @Override
      public void onCreate() {
          super.onCreate();
          Log.i(TAG, "onCreate");
          registerActivityLifecycleCallbacks(this);
      }
    
      @Override
      public void onMPaaSFrameworkInitFinished() {
          LoggerFactory.getTraceLogger().info(TAG, getProcessName());
      }
    
      @Override
      public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
          Log.i(TAG, "onActivityCreated");
      }
    
      @Override
      public void onActivityStarted(Activity activity) {
    
      }
    
      @Override
      public void onActivityResumed(Activity activity) {
    
      }
    
      @Override
      public void onActivityPaused(Activity activity) {
    
      }
    
      @Override
      public void onActivityStopped(Activity activity) {
    
      }
    
      @Override
      public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
    
      }
    
      @Override
      public void onActivityDestroyed(Activity activity) {
    
      }}
  2. In the AndroidManifest.xml file, ensure that the Application object inherits the Application object provided by mPaaS. Then, add the generated MyApplication class to meta-data whose key is mpaas.quinoxless.extern.application. The following sample code is for your reference.

     <application
     android:name="com.alipay.mobile.framework.quinoxless.QuinoxlessApplication" >
     <meta-data
              android:name="mpaas.quinoxless.extern.application"
              android:value="com.mpaas.demo.MyApplication"
              />
     </application>
  3. Import the Apache HTTP client.

    When you use Remote Procedure Call (RPC) or Hotpatch, you need to call the features of the Apache HTTP client. Therefore, add the following code to the AndroidManifest.xml file. For more information, see Use the Apache HTTP client.

    <uses-library android:name="org.apache.http.legacy" android:required="false"/>