All Products
Search
Document Center

Loading framework and customization

Last Updated: Apr 01, 2021

The mPaaS Android framework provides a complete set of loading logic. Based on this framework, R&D teams can develop multiple business lines. This topic describes the startup process of the framework and how to add your own code under the framework to start the docking.

Start the process

Application

When a traditional Android Package (APK) runs, the APK first loads the application configured in android:name of the application node in the AndroidManifest file.

Because the mPaaS Android framework rewrites the loading process, in android:name, configure the com.alipay.mobile.quinox.LauncherApplication class of the mPaaS Android framework.

  1. <application
  2. android:name="com.alipay.mobile.quinox.LauncherApplication"
  3. android:allowBackup="true"
  4. android:debuggable="true"
  5. android:hardwareAccelerated="false"
  6. android:icon="@drawable/appicon"
  7. android:label="@string/name"
  8. android:theme="@style/AppThemeNew" >
  9. </application>

Start page

It may be time-consuming for the framework to load the Bundle. Therefore, a startup page is needed to wait for the framework to start before jumping to the main page of the program. So the com.alipay.mobile.quinox.LauncherActivity application launch page provided by the framework is configured in the AndroidManifest file.

See the following configuration:

  1. <activity
  2. android:name="com.alipay.mobile.quinox.LauncherActivity"
  3. android:configChanges="orientation | keyboardHidden | navigation"
  4. android:screenOrientation="portrait"
  5. android:windowSoftInputMode="stateAlwaysHidden">
  6. <intent-filter>
  7. <action android:name="android.intent.action.MAIN" />
  8. <category android:name="android.intent.category.LAUNCHER" />
  9. </intent-filter>
  10. </activity>

The startup process of mPaaS is appropriately encapsulated, so that the developers can easily understand the startup process. In addition, the encapsulation avoids the startup process from being modified and deleted by mistake and interference. Therefore, the preceding LauncherApplication and LauncherActivity are completely invisible to developers.

In order for the client app to implement its own initialization logic during the startup process, mPaaS has designed the LauncherApplicationAgent and LauncherActivityAgent agents. As a developer, you can implement your own initialization logic in the corresponding callbacks by inheriting these two classes. When you define these two classes in the Bundle project, you need to configure anti-obfuscation settings for these two classes when using ProGuard for code obfuscation. For details, see Confusing Android files.

Startup flow chart

The loading process of the mPaaS Android framework is as follows:2

  1. After the framework starts, the main thread will create the launch page LauncherActivity, and then call back the preInit method of LauncherActivityAgent.
  2. The framework is performing multidex. During the process, the preInit method of LauncherApplicationAgent will be called back to read the description file of each Bundle in the current .apk. Corresponding class loaders will be created for each Bundle and the resource files in the loaders will be loaded.
  3. After the initialization is completed, call back the postInit methods of LauncherActivityAgent and LauncherApplicationAgent.

Custom

In fact, the framework has automatically created two classes in the Launcher project. MockLauncherApplicationAgent and MockLauncherActivityAgent inherited from these two callback APIs, LauncherApplicationAgent and LauncherActivityAgent. During the initialization of the framework, these two callback APIs are called in LauncherAppliction and LauncherActivity respectively.

Configure AndroidManifest.xml of Portal as follows. Developers can also implement these two agent classes in Bundle, and modify value corresponding to meta-data in the preceding configuration:

  1. <application
  2. android:name="com.alipay.mobile.quinox.LauncherApplication" >
  3. <! - Application callback configuration -->
  4. <meta-data
  5. android:name="agent.application"
  6. android:value="com.mpaas.demo.launcher.framework.MockLauncherApplicationAgent"/>
  7. <! - Activity callback configuration -->
  8. <meta-data
  9. android:name="agent.activity"
  10. android:value="com.mpaas.demo.launcher.framework.MockLauncherActivityAgent"/>
  11. <! - Layout configuration of the startup page -->
  12. <meta-data
  13. android:name="agent.activity.layout"
  14. android:value="layout_splash"/>
  15. </application>

Agent class

agent.application configures the startup process agent ApplicationAgent:

  1. public class MockLauncherApplicationAgent extends LauncherApplicationAgent {
  2. @Override
  3. protected void preInit() {
  4. super.preInit();
  5. //Before framework initialization
  6. }
  7. @Override
  8. protected void postInit() {
  9. super.postInit();
  10. //After framework initialization
  11. }
  12. }

The client apps can complete some application-level initialization tasks in the implementation class of LauncherApplicationAgent. The preInit() callback occurs before framework initialization. Therefore, do not invoke API operations related to the framework (MicroApplicationContext). However, the postInit() callback occurs after framework initialization and the relevant APIs can be used.

The agent.activity configures the agent for starting the activity:

  1. public class MockLauncherActivityAgent extends LauncherActivityAgent {
  2. @Override
  3. public void preInit(Activity activity) {
  4. super.preInit(activity);
  5. //Before the Launcher Activity is started
  6. }
  7. @Override
  8. public void postInit(final Activity activity) {
  9. super.postInit(activity);
  10. //After the Launcher Activity is started
  11. The logic for jumping to the program homepage
  12. startActivity(activity,YOUR_ACTIVITY);
  13. }
  14. }

Similar to the preceding LauncherApplicationAgent, two callbacks of LauncherActivityAgent occur before and after framework initialization respectively. And the usages are similar.

Modify the startup page layout

The layout file of the startup page is also configured in the AndroidManifest.xml of Portal:

  1. <application
  2. android:name="com.alipay.mobile.quinox.LauncherApplication" >
  3. <! - Layout configuration of the startup page -->
  4. <meta-data
  5. android:name="agent.activity.layout"
  6. android:value="layout_splash"/>
  7. </application>

Modify the value as the customized layout file name.

Note: The layout file and referenced related resources need to be placed in the Portal project.

Code sample