什么是 ActivityRecord ?android 的解释是 An entry in the history task, representing an activity
。大意是 ActivityRecord 是历史任务中的一个记录,代表着 activity,换言之,它是应用层的 activity 在 AMS 中的记录。
那么这个记录,也就是 ActivityRecord 需要记录哪些东西呢 ?
1、Activity 稳定不变的身份信息
这类信息是每个 Activity 出生就确定的,且不会改变,标识着一个 activity 的身份。就好比人的出生信息。这些信息有 info、packageName、icon 等
final ActivityInfo info; // activity info provided by developer in AndroidManifest
439 // The package implementing intent's component
440 // TODO: rename to mPackageName
441 final String packageName;
442 // the intent component, or target of an alias.
443 final ComponentName mActivityComponent;
private int icon; // resource identifier of activity's icon.
2、Activity 启动时基本信息
是指启动 Activity 时,才确定的信息,在每次启动时可能会不同。如 launchedFromPid、task、launchedFromPackage、processName。
这样说还是挺抽象的,如果把启动 activity 比作人进行一次外出的话,这类信息就是出发地、目的地、出行方式,在计划这次出行后才能确定。
final int launchedFromPid; // always the pid who started the activity.
449 final String launchedFromPackage; // always the package who started the activity.
455 final String processName; // process where this component wants to run
469 private Task task; // the task this is in.
3、Activity 过程耗时信息
在 activity 启动过程中,一些阶段的耗时信息。这类信息是只有阶段完成后才能统计确定。
470 private long createTime = System.currentTimeMillis();
471 long lastVisibleTime; // last time this activity became visible
472 long pauseTime; // last time we started pausing the activity
473 long launchTickTime; // base time for launch tick messages
474 long topResumedStateLossTime; // last time we reported top resumed state loss to an activity