android笔记-02 程序启动和Launcher

了解Activity的生命周期很久了,最近在网上学习了一下Activity的启动过程,和程序的启动过程,想知道当手机开机以后,手机进入到主页面,点击一个程序,这个程序是怎么启动的,在程序内部,Activity又是怎么跳转的,里面的东西太多,也只能了解个大概,然后写一下笔记:
在Android系统中,Launcher程序就是我们平时看到的桌面程序,它也是一个android程序,只不过这个应用程序是默认系统的第一个启动的应用程序,这里简单分析一下Launcher应用的启动流程。
不同的手机厂商定制android操作系统的时候都会更改Launcher的源代码,我们这里以android23的源码为例大致的分析一下Launcher的启动流程。
![这里写图片描述](https://img-blog.csdn.net/20160721150934177)
这张图很熟悉了吧,这不是就是eclipse中app项目的结构吗,里面点开AndroidManifest:
<application  
    android:name="com.android.launcher2.LauncherApplication"  
    ...  
    > 
<activity
            android:name="com.android.launcher2.Launcher"
            android:launchMode="singleTask"
            android:clearTaskOnLaunch="true"
            android:stateNotNeeded="true"
            android:theme="@style/Theme"
            android:windowSoftInputMode="adjustPan"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.MONKEY"/>
            </intent-filter>
        </activity>
此AndroidManifest正式android手机开机以后的启动程序配置文件,从中我们可以知道启动过程需要先后初始化LauncherApplication和Launcher的对象。更加简洁的说,启动过程可以分成两步,第一步在LauncherApplication.onCreate()方法中,第二部在Launcher.onCreate()方法中。
先来看LauncherApplication的代码:
public class LauncherApplication extends Application {
   
public void onCreate() {  
        super.onCreate();  
        // 在创建icon cache之前,我们需要判断屏幕的大小和屏幕的像素密度,以便创建合适大小的icon  
        final int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;  
        sIsScreenLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE ||  
            screenSize == Configuration.SCREENLAYOUT_SIZE_XLARGE;  
        sScreenDensity = getResources().getDisplayMetrics().density;  

        mIconCache = new IconCache(this);  
        mModel = new LauncherModel(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值