第三方SDK要求在onCreate中初始化 但是通过module扩展是不能使用onCreate这个生命周期得 要怎么做呢
4***@qq.com
- 发布:2019-08-03 23:58
- 更新:2021-03-19 15:16
- 阅读:3102
public class GlobalApplication implements UniAppHookProxy {
@Override
public void onCreate(Application application) {
//当前uni应用进程回调 仅触发一次 多进程不会触发
//可通过UniSDKEngine注册UniModule或者UniComponent
//初始化 Adjust SDK
String appToken = "${token}";
String environment = AdjustConfig.ENVIRONMENT_SANDBOX;
AdjustConfig config = new AdjustConfig(application, appToken, environment);
Adjust.onCreate(config);
Log.i("AdjustConfig", "成功初始化!");
application.registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());
}
@Override
public void onSubProcessCreate(Application application) {
//其他子进程初始化回调 可用于初始化需要子进程初始化需要的逻辑
//初始化 Adjust SDK
String appToken = "k1ocmqx4zke8";
String environment = AdjustConfig.ENVIRONMENT_SANDBOX;
AdjustConfig config = new AdjustConfig(application, appToken, environment);
Adjust.onCreate(config);
Log.i("AdjustConfig", "成功初始化!");
application.registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());
}
private static final class AdjustLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityResumed(Activity activity) {
Adjust.onResume();
}
@Override
public void onActivityPaused(Activity activity) {
Adjust.onPause();
}
@Override
public void onActivityStopped(@NonNull Activity activity) {
}
@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
}
@Override
public void onActivityDestroyed(@NonNull Activity activity) {
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(@NonNull Activity activity) {
}
//...
}
}
MX2021
public class RichAlert_AppProxy implements UniAppHookProxy {
@Override
public void onCreate(Application application) {
//当前uni应用进程回调 仅触发一次 多进程不会触发
//可通过UniSDKEngine注册UniModule或者UniComponent
}
@Override
public void onSubProcessCreate(Application application) {
//其他子进程初始化回调 可用于初始化需要子进程初始化需要的逻辑
}
}
onCreate里面的application参数就是application对象,填入第三方sdk的this参数作为实体类传进去就可以了
2021-03-19 15:13
MX2021
onCreate, onSubProcessCreate各放一份
2021-03-19 15:13