All Products
Search
Document Center

Initialize mPaaS

Last Updated: Dec 16, 2021

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
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        QuinoxlessFramework.setup(this, new IInitCallback() {
            @Override
            public void onPostInit() {
                // Start writing the code to use features of the mPaaS framework here.
            }
        });
    }

    @Override
    public void onCreate() {
        super.onCreate();
        QuinoxlessFramework.init();
    }

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"/>