All Products
Search
Document Center

Initialize mPaaS

Last Updated: Mar 10, 2021

About this topic

Before you use mPaaS framework, initialize the Application object. The initialization process varies based on whether Hotpatch is enabled. Therefore, this topic describes both the initialization processes when Hotpatch is not enabled and when it is.

Initialization process when Hotpatch is not enabled

If Hotpatch is not enabled, you only need to add the following code to the Application object:

  1. @Override
  2. protected void attachBaseContext(Context base) {
  3. super.attachBaseContext(base);
  4. QuinoxlessFramework.setup(this, new IInitCallback() {
  5. @Override
  6. public void onPostInit() {
  7. // Write the code to use features of the mPaaS framework.
  8. }
  9. });
  10. }
  11. @Override
  12. public void onCreate() {
  13. super.onCreate();
  14. QuinoxlessFramework.init();
  15. }

Initialization process when Hotpatch is enabled

If Hotpatch is enabled, you must further perform the following procedure.

Procedure

  1. Use QuinoxlessApplicationLike to re-extend the Application object. Do not confuse this class with another class. The following code snippet uses the “MyApplication” object as an example.

    1. @Keep
    2. public class MyApplication extends QuinoxlessApplicationLike implements Application.ActivityLifecycleCallbacks {
    3. private static final String TAG = "MyApplication";
    4. @Override
    5. protected void attachBaseContext(Context base) {
    6. super.attachBaseContext(base);
    7. Log.i(TAG, "attacheBaseContext");
    8. }
    9. @Override
    10. public void onCreate() {
    11. super.onCreate();
    12. Log.i(TAG, "onCreate");
    13. registerActivityLifecycleCallbacks(this);
    14. }
    15. @Override
    16. public void onMPaaSFrameworkInitFinished() {
    17. LoggerFactory.getTraceLogger().info(TAG, getProcessName());
    18. }
    19. @Override
    20. public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
    21. Log.i(TAG, "onActivityCreated");
    22. }
    23. @Override
    24. public void onActivityStarted(Activity activity) {
    25. }
    26. @Override
    27. public void onActivityResumed(Activity activity) {
    28. }
    29. @Override
    30. public void onActivityPaused(Activity activity) {
    31. }
    32. @Override
    33. public void onActivityStopped(Activity activity) {
    34. }
    35. @Override
    36. public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
    37. }
    38. @Override
    39. public void onActivityDestroyed(Activity activity) {
    40. }}
  2. In the AndroidManifest.xml file, point the Application object to the Application object provided by mPaaS. Add the generated “MyApplication” class to the meta-data whose key is mpaas.quinoxless.extern.application. See the following examples:

    1. <application
    2. android:name="com.alipay.mobile.framework.quinoxless.QuinoxlessApplication" >
    3. <meta-data
    4. android:name="mpaas.quinoxless.extern.application"
    5. android:value="com.mpaas.demo.MyApplication"
    6. />
    7. </application>
  3. Introduce the Apache HTTP client.

    When RPC or Hotpatch is enabled, relevant features of the Apache HTTP client are required during the initialization process. You only need to add the following code to the AndroidManifest.xml file. For more information, see Apache HTTP client.

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