main函数
public static void main(String[] args) {
....
// 初始化
Environment.initForCurrentUser();
// 初始化
Environment.getUserConfigDirectory(UserHandle.myUserId());
TrustedCertificateStore.setDefaultUserDirectory(configDir);
// 初始化
initializeMainlineModules();
Process.setArgV0("<pre-initialized>");
// 初始化
Looper.prepareMainLooper();
// 初始化
long startSeq = 0;
if (args != null) {
for (int i = args.length - 1; i >= 0; --i) {
if (args[i] != null && args[i].startsWith(PROC_START_SEQ_IDENT)) {
startSeq = Long.parseLong(
args[i].substring(PROC_START_SEQ_IDENT.length()));
}
}
}
// 初始化 因为main函数是个静态方法,因此ActivityThread要实例化,必须通过new运算实现
ActivityThread thread = new ActivityThread();
thread.attach(false, startSeq);
// 初始化
if (sMainThreadHandler == null) {
sMainThreadHandler = thread.getHandler();
}
...
// 进入无限循环
Looper.loop();
throw new RuntimeException("Main thread loop unexpectedly exited");
}