ActivityRecord 是 Activity 的标识,与每个 Activity 是一一对应的。下面我们来介绍它的创建过程。既然是代表 Activity,那么肯定是在启动 Activity 的时候来创建的。
Step 1: ActivityStackSupervisor.java
在 startActivityLocked 方法中,首先创建 ActivityRecord 对象:
final int startActivityLocked(IApplicationThread caller,
Intent intent, String resolvedType, ActivityInfo aInfo,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
IBinder resultTo, String resultWho, int requestCode,
int callingPid, int callingUid, String callingPackage,
int realCallingPid, int realCallingUid, int startFlags, Bundle options,
boolean componentSpecified, ActivityRecord[] outActivity, ActivityContainer container,
TaskRecord inTask) {
ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage,
intent, resolvedType, aInfo, mService.mConfiguration, resultRecord, resultWho,
requestCode, componentSpecified, this, container, options);
err = startActivityUncheckedLocked(r, sourceRecord, voiceSession, voiceInteractor,
startFlags, true, options, inTask);
}
ActivityRecord 构造函数参数说明:
ActivityRecord( ActivityManagerService _service,
ProcessRecord _caller, // 调用者的进程,与 aInfo 一起来决定当前 Activity 的应用包名
int _launchedFromUid, // 启动 Activity 的 Uid
String _launchedFromPackage, // 启动 Activity 的包名
Intent _intent, // 启动的 Intent
String _resolvedType, // 调用的包名
ActivityInfo aInfo, // Activity 的信息
Configuration _configuration,
ActivityRecord _resultTo,
String _resultWho,
_reqCode,
_componentSpecified,
ActivityStackSupervisor supervisor,
ActivityContainer container,
Bundle options)

