Activity 创建流程分析
在前两篇文章中我们谈到了从桌面点击图标到启动进程以及启动ActivityThread再到ActivityThread启动Activity的过程分析
1. 安卓应用启动流程分析
2. ActivityThread启动页面分析
本片文章可谓是紧接着上面两篇文章,上文说到的ActivityThread performLaunchActivity(),今天继续讲从这里如何创建Activity 的。
private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) {
。。。
if (r.profileFd != null) {
mProfiler.setProfiler(r.profileFile, r.profileFd);
mProfiler.startProfiling();
mProfiler.autoStopProfiler = r.autoStopProfiler;
}
handleConfigurationChanged(null, null);
//上节提到,我们ActivityThread开启来之后呢,开启Activity 的入口在这里,那么我们还是继续深入其中,看看他又做了什么操作。
Activity a = performLaunchActivity(r, customIntent);
if (a != null) {
r.createdConfig = new Configuration(mConfiguration);
Bundle oldState = r.state;
handleResumeActivity(r.token, false, r.isForward);
。。。
} else {
try {
ActivityManagerNative.getDefault()
.finishActivity(r.token, Activity.RESULT_CANCELED, null);
} catch (RemoteException ex) {
// Ignore
}
}
}
private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
ActivityInfo aInfo = r.activityInfo;
if (r.packageInfo == null) {
r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo,