1、android在编译过程中会在framework/base下生成preloaded-classes,在zygoteint进程运行时,会根据此文件进行java文件预装载。
# Classes which are preloaded by com.android.internal.os.ZygoteInit.
# Automatically generated by frameworks/base/tools/preload/WritePreloadedClassFile.java.
# MIN_LOAD_TIME_MICROS=1250
# MIN_PROCESSES=10
android.R$styleable
android.accounts.Account
android.accounts.Account$1
android.accounts.AccountManager
android.accounts.AccountManager$12
android.accounts.AccountManager$13
android.accounts.AccountManager$6
android.accounts.AccountManager$AmsTask
android.accounts.AccountManager$AmsTask$1
android.accounts.AccountManager$AmsTask$Response
android.accounts.AccountManagerFuture
android.accounts.IAccountManager
android.accounts.IAccountManager$Stub
android.accounts.IAccountManager$Stub$Proxy
android.accounts.IAccountManagerResponse
android.accounts.IAccountManagerResponse$Stub
android.accounts.OnAccountsUpdateListener
android.animation.Animator
android.animation.Animator$AnimatorListener
android.animation.AnimatorListenerAdapter
android.animation.AnimatorSet
android.animation.AnimatorSet$AnimatorSetListener
android.animation.AnimatorSet$Builder
android.animation.AnimatorSet$DependencyListener
android.animation.AnimatorSet$Node
android.animation.FloatEvaluator
android.animation.FloatKeyframeSet
android.animation.IntEvaluator
android.animation.IntKeyframeSet
android.animation.Keyframe
android.animation.Keyframe$FloatKeyframe
android.animation.Keyframe$IntKeyframe
android.animation.KeyframeSet
android.animation.LayoutTransition$TransitionLis
这个文件是通过framework/base/tools/preload/WritePreloadedClassFile.java类生成。
2、preload-resources:
zygoteint进程在运行中,除了预装载java文件还会预装载资源。在Resources对象中完成。
3、SystemServer是zygote进程孵化的第一个进程。systemServer初始化了android系统中大部分系统服务。例如WifiService,WIndowManagerService等。
4、启动第一个activity。
ActivityManagerService在android启动时以调用systemReady方法进行结束,在这个方法的最后,执行了如下代码,进而启动了android第一个acitivty
mStackSupervisor.resumeTopActivitiesLocked();
进而:
boolean resumeTopActivitiesLocked() {
return resumeTopActivitiesLocked(null, null, null);
}
boolean resumeTopActivitiesLocked(ActivityStack targetStack, ActivityRecord target,
Bundle targetOptions) {
if (targetStack == null) {
targetStack = getFocusedStack();
}
boolean result = false;
for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
final ActivityStack stack = mStacks.get(stackNdx);
if (isFrontStack(stack)) {
if (stack == targetStack) {
result = stack.resumeTopActivityLocked(target, targetOptions);
} else {
stack.resumeTopActivityLocked(null);
}
}
}
return result;
}
进而调用resumeTopActivityLocked:
final boolean resumeTopActivityLocked(ActivityRecord prev) {
return resumeTopActivityLocked(prev, null);
}
final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
// Find the first activity that is not finishing.
ActivityRecord next = topRunningActivityLocked(null);
// Remember how we'll process this pause/resume situation, and ensure
// that the state is reset however we wind up proceeding.
final boolean userLeaving = mStackSupervisor.mUserLeaving;
mStackSupervisor.mUserLeaving = false;
if (next == null) {
// There are no more activities! Let's just start up the
// Launcher...
ActivityOptions.abort(options);
if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: No more activities go home");
if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
return final boolean resumeTopActivityLocked(ActivityRecord prev) {
return resumeTopActivityLocked(prev, null);
}
final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
// Find the first activity that is not finishing.
ActivityRecord next = topRunningActivityLocked(null);
// Remember how we'll process this pause/resume situation, and ensure
// that the state is reset however we wind up proceeding.
final boolean userLeaving = mStackSupervisor.mUserLeaving;
mStackSupervisor.mUserLeaving = false;
if (next == null) {
// There are no more activities! Let's just start up the
// Launcher...
ActivityOptions.abort(options);
if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: No more activities go home");
if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
return mStackSupervisor.resumeHomeActivity(prev);
}
}
进而调用
mStackSupervisor.resumeHomeActivity(prev);
启动home 主界面Launcher程序