Android Launcher 启动简述 <2>
来源:互联网 发布:软件如何防卸载 编辑:程序博客网 时间:2024/05/17 07:32
Lanucher就是我们平时的开机后的桌面APP(它其实就是一个APP,没什么特别的,看起来有点高大上),作为APP程序,它也需要启动自己的Activity界面(因为桌面是能够看得见的,有界面的).那么开机时如何启动呢?
根据上一篇,开机时SystemServer会将ActivityManagerService启动,那么首先就会启动SystemReady(...)方法.
public void systemReady(final Runnable goingCallback) {
里面的程序非常的多,大概判断了FactoryTest,Binder,SystemUI一些,还有一些记录信息,但是只需要看到最后面:
mMainStack.resumeTopActivityLocked(null);
看过前面一篇的,对应上面这句话不会陌生的.接下来转到ActivityStack类中:不过记住上面传递的参数为null
final boolean resumeTopActivityLocked(ActivityRecord prev) { return resumeTopActivityLocked(prev, null); } final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) { // Find the first activity that is not finishing. ActivityRecord next = topRunningActivityLocked(null); // Remember how we'll process this pause/resume situation, and ensure // that the state is reset however we wind up proceeding. final boolean userLeaving = mUserLeaving; mUserLeaving = false; if (next == null) { // There are no more activities! Let's just start up the // Launcher... if (mMainStack) { ActivityOptions.abort(options); return mService.startHomeActivityLocked(mCurrentUser); } }
前面传递的参数为null,发现参数是ActivityRecord,那么就是很容易,现在系统里面还没有任何运行过的Activity记录,当然显而易见,刚开机怎么可能有运行Activity记录呢?
那么下面的程序next==null自然而然就是成立的,然后又要装到ActivityManagerService类:
boolean startHomeActivityLocked(int userId) { if (mHeadless) { // Added because none of the other calls to ensureBootCompleted seem to fire // when running headless. ensureBootCompleted(); return false; } if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL && mTopAction == null) { // We are running in factory test mode, but unable to find // the factory test app, so just sit around displaying the // error message and don't try to start anything. return false; } Intent intent = new Intent( mTopAction, mTopData != null ? Uri.parse(mTopData) : null); intent.setComponent(mTopComponent); if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) { intent.addCategory(Intent.CATEGORY_HOME); } ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId); if (aInfo != null) { intent.setComponent(new ComponentName( aInfo.applicationInfo.packageName, aInfo.name)); // Don't do this if the home app is currently being // instrumented. aInfo = new ActivityInfo(aInfo); aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId); ProcessRecord app = getProcessRecordLocked(aInfo.processName, aInfo.applicationInfo.uid); if (app == null || app.instrumentationClass == null) { intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); mMainStack.startActivityLocked(null, intent, null, aInfo, null, null, 0, 0, 0, 0, null, false, null); } } return true; }
最后的mMainStack.startActivityLocked(...)就会启动Launcher APP,这个在上面的程序中打印出log信息,后面的startActivityLocked和前一篇的是一样的了.
private final void startActivityLocked(ActivityRecord r, boolean newTask, boolean doResume, boolean keepCurTransition, Bundle options) { final int NH = mHistory.size(); int addPos = -1; if (!newTask) { // If starting in an existing task, find where that is... boolean startIt = true; for (int i = NH-1; i >= 0; i--) { ActivityRecord p = mHistory.get(i); if (p.finishing) { continue; }
打印log出上面NH的值会是等于0,因为Launcher是第一个启动的Activity.
这里面特别强调的是mHistory是ArrayList<ActivityRecord>,记录了启机以后所有Activity的运行状态信息,每启动一个Activity就会对应有一个ActivityRecord将其所有的状态和信息记录下来,并且将这个new的ActivityRecord添加到mHistory集合中.启动机器后,mHistory中肯定是空的,所以NH=0.
- Android Launcher 启动简述 <2>
- Android 启动Launcher
- Android启动Launcher过程
- 【Android】launcher启动参数
- android 启动launcher流程
- android启动过程简述
- Android 启动简述
- 简述Android启动模式
- Android 获取Launcher 启动列表
- Android--launcher启动过程解析
- Android--launcher启动过程解析
- android launcher启动及开发
- Android—launcher 启动流程
- Android笔记 - Android启动之Launcher启动
- Android 启动过程的简述
- Android launcher -- 调试运行launcher源码 2
- Android launcher -- launcher源码修改 2
- android Launcher——启动过程详解
- 绑定KVM虚拟机的vcpu与物理CPU
- 认证模式之Digest模式
- Beego走起(二) 路由的简单设置
- java使用线程请求访问每次间隔10分钟连续5次,之后停止请求
- 搜索—Problem_1013&1014-A strange lift
- Android Launcher 启动简述 <2>
- Nema协议校验码算法
- Redis简介
- 转:Android NDK开发之Jni调用Java对象
- Node 学习笔记之事件发射器
- c++导出自定义类到lua中的一些底层实现
- Fragment的生命周期
- fastDFS安装
- 认证模式之Form模式