mPaaS Android framework provides a complete set of loading logics. You can implement multiple-business development on the basis of this framework. This guide introduces the framework startup process and describes how to add your codes to the framework to enable startup.
Startup process
Application
When traditional Android apk starts running, the Application configured in android:name
of application
node in the AndroidManifest
file is firstly loaded.
Since mPaaS Android framework has overridden the loading process, what configured in android:name
should be the com.alipay.mobile.quinox.LauncherApplication
class of mPaaS Android framework.
<application
android:name="com.alipay.mobile.quinox.LauncherApplication"
android:allowBackup="true"
android:debuggable="true"
android:hardwareAccelerated="false"
android:icon="@drawable/appicon"
android:label="@string/name"
android:theme="@style/AppThemeNew" >
</application>
Startup page
Since it may be time-consuming for the framework to load the bundle, a startup page is required to redirect you to the application homepage when framework startup is completed. Therefore, the com.alipay.mobile.quinox.LauncherActivity
application startup page that is provided by the mPaaS framework is configured in the AndroidManifest
file.
The configuration is as follows:
<activity
android:name="com.alipay.mobile.quinox.LauncherActivity"
android:configChanges="orientation | keyboardHidden | navigation"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To make developers have a better understanding of the startup process and avoid that the startup process is modified, deleted, or disturbed by mistake, the startup process of mPaaS is moderately encapsulated. So, the above LauncherApplication
and LauncherActivity
are invisible to the developers.
To enable that the client App implements its own initialization logic during the startup process, LauncherApplicationAgent
and LauncherActivityAgent
agents are designed in mPaaS. You can implement the App’s own initialization logic in the corresponding callback by inheriting the two classes. If you have defined these two classin bundle project, anti-obfuscation settings need to be done for these two classes when using ProGuard for code obfuscation, for more information, see Obfuscate Android codes.
Startup flow chart
The procedure of loading mPaaS Android framework is as follows:
When the framework is started, the main thread creates a startup page
LauncherActivity
, and then calls back thepreInit
method ofLauncherActivityAgent
.The framework enables multidex. In the process, the framework calls back the
preInit
method ofLauncherApplicationAgent
, reads the description file of each bundle in the current.apk
file, and creates the corresponding class loaders for all bundles.After initialization, the framework calls the
postInit
methods ofLauncherActivityAgent
andLauncherApplicationAgent
.
Customization
Actually, the framework has created two classes (MockLauncherApplicationAgent
and MockLauncherActivityAgent
) in Launcher project, and the two classes respectively inherit LauncherApplicationAgent
and LauncherActivityAgent
callback interfaces. Both interfaces are respectively called in LauncherAppliction
and LauncherActivity
during framework initialization.
Configure the AndroidManifest.xml
file of the Portal as follows. You can also implement these two delegate classes in the Bundle, and modify the value
of the corresponding meta-data
in the above configuration.
<application
android:name="com.alipay.mobile.quinox.LauncherApplication" >
<!-- Callback configuration of Application -->
<meta-data
android:name="agent.application"
android:value="com.mpaas.demo.launcher.framework.MockLauncherApplicationAgent"/>
<!-- Callback configuration of Activity -->
<meta-data
android:name="agent.activity"
android:value="com.mpaas.demo.launcher.framework.MockLauncherActivityAgent"/>
<!-- Layout configuration of the startup page -->
<meta-data
android:name="agent.activity.layout"
android:value="layout_splash"/>
</application>
Delegate classes
What configured in agent.application
is the startup process delegate ApplicationAgent
, shown as follows:
public class MockLauncherApplicationAgent extends LauncherApplicationAgent {
@Override
protected void preInit() {
super.preInit();
//Before framework initialization
}
@Override
protected void postInit() {
super.postInit();
//After framework initialization
}
}
The client App can perform application-level initialization in the implementation class of LauncherApplicationAgent
. preInit()
callback occurs before the framework initialization, so do not call the relevant interfaces of the framework (MicroApplicationContext
) here. However, postInit()
callback occurs after the framework initialization, you can use it.
What configured in agent.activity
is the delegate of startup Activity, shown as follows:
public class MockLauncherActivityAgent extends LauncherActivityAgent {
@Override
public void preInit(Activity activity) {
super.preInit(activity);
//Before Launcher Activity startup
}
@Override
public void postInit(final Activity activity) {
super.postInit(activity);
//After Launcher Activity startup
//The logic of jumping to the homepage
startActivity(activity,YOUR_ACTIVITY);
}
}
Similar to LauncherApplicationAgent
, the two callback of LauncherActivityAgent
respectively happens before and after the framework initailization, and the methods used are also similar.
Modify startup page layout
The layout file of the startup page is also configured in the AndroidManifest.xml
file of the Portal, shown as follows.
<application
android:name="com.alipay.mobile.quinox.LauncherApplication" >
<!-- Layout configuration of the startup page -->
<meta-data
android:name="agent.activity.layout"
android:value="layout_splash"/>
</application>
Modify the value
to the name of the custom layout file.
You need to put the layout file and the relevant resources that are referenced in the Portal project.