导航栏创建的最终点在SystemUI的NavigationBar.java类里。那么创建的起点在哪里呢?在SystemServer 里。在 SystemServer 自动系统服务时,分成了四个方法:
startBootstrapServices(t);startCoreServices(t);startOtherServices(t);startApexServices(t);
SystemUI是在startOtherServices的最后启动的,调用startSystemUi()方法,然后调用Context.startServiceAsUser()完成启动。
public class SystemUIService extends Service
然后会进入SystemUIService的onCreate()方法中。SystemUIService除了onCreate()方法,其他方法意义不大,可见SystemUIService是一个容器。这里先贴一个堆栈。
onCreate()方法中调用SystemUIApplication.startSystemUserServicesIfNeeded()方法。
sortedStartables保存的是子服务的一些信息。
startServicesIfNeeded()方法中执行启动子服务的方法。
startStartable()方法中运行子服务。
然后会走到CentralSurfacesImpl.java类中。CentralSurfacesImpl是个单例。
public classCentralSurfacesImplimplementsCoreStartable, CentralSurfaces{}
然后走进createAndAddWindows()方法中。
然后走进makeStatusBarView()方法中。然后走进createNavigationBar()方法中。然后使用NavigationBarController.createNavigationBars()方法去创建导航栏。NavigationBarController是个接口,有两个实现类,NavigationBarControllerImpl是手机上使用的。
然后走进createNavigationBar()方法中。然后走进NavigationBar.init()方法中。NavigationBar继承自ViewController,会走进ViewController.init()方法中。NavigationBar重写了onInit()方法,就会走到开头说的终点。