优化的过程中看到了
01-04 18:23:32.396 10011-10011/? D/appmoduleInit: com.***.***
01-04 18:23:34.201 10011-10011/***.***.*** D/appmoduleInit: 2
01-04 18:23:36.086 10178-10178/com.***.***:remote D/appmoduleInit: ***.***.***:remote
01-04 18:23:38.596 10178-10178/***.***.***:remote D/appmoduleInit: 2
application初始化了两次,解决办法要么AndroidManifest.xml文件中找到android:process=":remote"
,注释掉对已的Component,即可解决。如果组件是App必须的,那么在Application的初始化过程中获取到进程的名称
private String getCurProcessName(Context context) {
int pid = android.os.Process.myPid();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess:activityManager.getRunningAppProcesses()) {
if (appProcess.pid == pid) {
return appProcess.processName;
}
}
return "";
}
通过判断跳过第二次的初始化逻辑。