Android 7.0 Launcher3的启动和加载流程分析

本文的分析基于MTK提供的Android 7.0源码,并非Google官方提供的源码,其中可能有一些小的差异,还望谅解。
Launcher的本质就是一个普通应用,它比普通应用多配置了Category的Android:name=”android.intent.category.HOME”属性,之后ActivityManagerService的startHomeActivityLocked方法将启动含有这个属性的Activity。

boolean startHomeActivityLocked(int userId) {
        if(this.mHeadless) {
            this.ensureBootCompleted();
            return false;
        } else if(this.mFactoryTest == 1 && this.mTopAction == null) {
            return false;
        } else {
            Intent intent = new Intent(this.mTopAction, this.mTopData != null?Uri.parse(this.mTopData):null);
            intent.setComponent(this.mTopComponent);
            if(this.mFactoryTest != 1) {
                intent.addCategory("android.intent.category.HOME");
            }
            ActivityInfo aInfo = intent.resolveActivityInfo(this.mContext.getPackageManager(), 1024);
            if(aInfo != null) {
                intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
                aInfo = new ActivityInfo(aInfo);
                aInfo.applicationInfo = this.getAppInfoForUser(aInfo.applicationInfo, userId);
                ProcessRecord app = this.getProcessRecordLocked(aInfo.processName, aInfo.applicationInfo.uid);
                if(app == null || app.instrumentationClass == null) {
                    intent.setFlags(intent.getFlags() | 268435456);
                    this.mMainStack.startActivityLocked((IApplicationThread)null, intent, (String)null, aInfo, (IBinder)null, (String)null, 0, 0, 0, 0, (Bundle)null, false, (ActivityRecord[])null);
                }
            }  
   return true;
      }
 }

这里贴出一篇关于ActivityManagerService启动Activity的博文:
http://blog.csdn.net/gaugamela/article/details/53183216

接下来看看Launcher界面的划分。Launcher3实质其实就是一个Activity包含N个自定义的View。
Launcher3界面
结合图和布局文件可能更好理解Launcher3的界面

<com.android.launcher3.LauncherRootView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res-auto"
    android:id="@+id/launcher"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <com.android.launcher3.DragLayer
        android:id="@+id/drag_layer"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.android.launcher3.FocusIndicatorView
            android:id="@+id/focus_indicator"
            android:layout_width="52dp"
            android:layout_height="52dp" />
        <!-- The workspace contains 5 screens of cells -->
        <!-- DO NOT CHANGE THE ID -->
        <com.android.launcher3.Workspace
            android:id="@+id/workspace"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            launcher:defaultScreen="@integer/config_workspaceDefaultScreen"
            launcher:pageIndicator="@+id/page_indicator">
        </com.android.launcher3.Workspace>

        <!-- DO NOT CHANGE THE ID -->
        <include layout="@layout/hotseat"
            android:id="@+id/hotseat"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <include layout="@layout/overview_panel"
            android:id="@+id/overview_panel"
            android:visibility="gone" />
        <!-- Keep these behind the workspace so that they are not visible when
             we go into AllApps -->
        <include
            android:id="@+id/page_indicator"
            layout=
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值