zoukankan      html  css  js  c++  java
  • Android的Launcher启动流程 “Launcher部分启动流程”

    研究代码从:AndroidManifest.xml、自定义的Application.java开始。

    Android系统启动时,系统需要一个Home应用程序来负责将这些应用程序展示出来;也就是该应用的目的在于:Android系统启动后,第一个启动的应用程序。在Android系统中,这个默认的Home应用程序就是Launcher。

    要把某个应用程序作为Home,只需要在Android.xml文件中添加一个category:

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="com.aliyun.ushell.action.detailpage" />
    </intent-filter>

    对于AndroidManifest.xml文件中的几个属性说明:

    <manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.aliyun.ushell"  coreApp="true" android:sharedUserId="android.uid.system"
        android:versionCode="2"
        android:versionName="1.2.3" 
        >

    其中android:sharedUserId决定是否需要系统签名;android:theme决定整个应用的theme和style;andrid:debuggable决定应用是否处于调试模式。

    疑问:

    1. Launcher是如何被启动的?Android系统为什么在启动时会默认启动Launcher?

    2. Launcher主要做什么工作?

    Android系统开机会启动Launcher,Launcher是由ActivityManager启动的,而ActivityManager是由SystemServer启动。

    此处就用到了在AndroidManifest.xml文件中添加的intent-filter属性值:category_home。一般绑定使用上述的三个category,也就是关键词:main/default/home。

    Launcher的主要工作是:监听应用的安装、更新、删除等导致Launcher数据库变化的操作。Launcher数据都是使用ContentProvider来提供数据,也就是需要自定义ContentResolver监听指定Uri数据的变化。

    private final ContentObserver mObserver = new ContentObserver(new Handler()) {
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            final int nightSwitch = Global.getInt(UShellApplication.this.getContentResolver(), SWITCH_KEY, -1);
            final int nightOn = Global.getInt(UShellApplication.this.getContentResolver(), ON_KEY, -1);
            final boolean wallpaperOn = (Global.getInt(UShellApplication.this.getContentResolver(), WALLPAPER_KEY, DEFAULT_WALLPAPER) == 1);
            mWallpaperOn = wallpaperOn;
            if (readTime() || nightSwitch != mNightSwitch || nightOn != mNightOn) {
                mNightSwitch = nightSwitch;
                mNightOn = nightOn;
                if (!Utilities.IS_ZHONGHONG) {
                    onTimeChanged();
                } else {
                    onZHChanged(null);
                }
            }
        }
    };

    Launcher启动的过程主要就是加载界面数据然后显示出来,界面数据都是系统App有关的数据(可能包含Launcher数据库)。

  • 相关阅读:
    第一节:Node.js简介
    Socket实现java服务端与AndroidApp端数据交互
    zz Android Studio --“Cannot resolve symbol” 解决办法
    git 阿里云代码托管
    zzvisual studio系列(vs)启动调试网站使用ip+端口局域网访问
    阿里云的域名给七牛云的配置CDN和ssl
    win10 visual studio IIS Express 局域网调试,默认只能localhost
    window2012 iis8.0 配置https 默认居然是TLS1.1
    andriod 连接wcf ,HttpURLConnection FileNotFoundException
    zzWCF实现RESTFul Web Service
  • 原文地址:https://www.cnblogs.com/CVstyle/p/6395694.html
Copyright © 2011-2022 走看看