mPaaS initialization requires modifying the Application object. The steps differ depending on whether you use the hotpatching feature.
Without the hotpatching feature
Prerequisites: Your app has a custom Application class. No obfuscation configuration is required for this path.
In your Application class, override onCreate() and call MP.init():
@Override
public void onCreate() {
super.onCreate();
MP.init(
this,
MPInitParam.obtain().setCallback(new MPInitParam.MPCallback() {
@Override
public void onInit() {
Log.d("TAG", "mPaaS init finished");
}
})
);
}
If you are integrating with Kotlin, use the mPaaS KTX extension. For more information, see mPaaS Kotlin extension.
If you continue to use the
QuinoxlessFrameworkinitialization method, your calls are not affected. No changes to your code or business logic are required.
Do not filter processes before calling MP.init. The initialization code must run in the main process, the tools child process, and the push child process.
Using the hotpatching feature
Prerequisites: Your project has ProGuard or R8 configured. The @Keep annotation is available.
-
Modify the Application object to inherit from
QuinoxlessApplicationLike. Annotate the class with@Keepto prevent obfuscation.This example uses
MyApplicationas the class name:@Keep // Required: prevents ProGuard/R8 from obfuscating this class public class MyApplication extends QuinoxlessApplicationLike implements Application.ActivityLifecycleCallbacks { private static final String TAG = "MyApplication"; @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // Required: mPaaS hooks into base context here Log.i(TAG, "attacheBaseContext"); } @Override public void onCreate() { super.onCreate(); Log.i(TAG, "onCreate"); registerActivityLifecycleCallbacks(this); } @Override public void onMPaaSFrameworkInitFinished() { // Called when the mPaaS framework finishes initialization 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) { }} -
In the
AndroidManifest.xmlfile, set the application to the mPaaS-providedApplicationobject, then registerMyApplicationunder themeta-datakeympaas.quinoxless.extern.application:<application android:name="com.alipay.mobile.framework.quinoxless.QuinoxlessApplication" > <meta-data android:name="mpaas.quinoxless.extern.application" android:value="com.mpaas.demo.MyApplication" /> </application> -
Import the Apache HTTP client.
The RPC and hotpatching features require the Apache HTTP client. Add the following code to the
AndroidManifest.xmlfile. For more information, see Use the Apache HTTP client.<uses-library android:name="org.apache.http.legacy" android:required="false"/>