10.3.4 调用startRunning方法
ActivityManagerService启动过程的第四步由startRunning方法完成,其代码如下:
public final class ActivityManagerService extends ActivityManagerNative
implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback{
……
//本例中,传入的4个参数都是null
public final void startRunning(String pkg, String cls, String action, String data){
synchronized(this){
/mStartRunning的初始值为false,只有执行startRunning方法后才会赋值为true/
if(mStartRunning){
return;
}
mStartRunning=true;
/由于传入的pkg和cls参数均为null,所以最终mTopComponent也为null/
mTopComponent=pkg!=null&&cls!=null
?new ComponentName(pkg, cls):null;
/传入的action参数为null,因此mTopAction赋值为ACTION_MAIN/
mTopAction=action!=null?action:Intent.ACTION_MAIN;
/传入的data参数为null,因此mTopData也为null/
mTopData=data;
/*mSystemReady初始值为false,只有在执行systemReady方法后
才会赋值为true。因此执行到这里便直接返回了/
if(!mSystemReady){
return;
}
}
/暂时不执行,即mSystemReady不会赋值为true。这个方法很重要,后续也会涉及/
systemReady(null);
}
startRunning方法很简单,其关键操作是将mStartRunning成员变量赋值为true,标识ActivityManagerService处于运行状态,同时也标记ActivityManagerService的main方法执行完毕。接下来程序返回ServerThread的run方法,进而执行ActivityManagerService运行过程的第二阶段。