LauncheProvider解析
LauncherProvider解析
Launcher是由ActivityManagerService启动的,而ActivityManagerService和PackageManagerService一样,都是在开机时由SystemServer组件启动的,SystemServer组件首先是启动PackageManagerServic,由它来负责安装系统的应用程序,系统中的应用程序安装好了以后,SystemServer组件接下来就要通过ActivityManagerService来启动Home应用程序Launcher了,Launcher在启动的时候便会通过PackageManagerServic把系统中已经安装好的应用程序以快捷图标的形式展示在桌面上,这样用户就可以使用这些应用程序了。
一、整个Launcher的入口点
1、LauncherApplication.java
继承了Application类,当整个Launcher启动时,它就是整个程序的入口。由AndroidManifest.xml文件可以看到整个Launcher的代码结构,如下:
在AndroidManifest.xml中的配置
android:name="com.android.launcher2.LauncherApplication"
android:label="@string/application_name"
android:icon="@drawable/ic_launcher_home"
android:hardwareAccelerated="@bool/config_hardwareAccelerated"
android:largeHeap="@bool/config_largeHeap">
android:name:指定了整个Launcher的Application也就是入口是在 com.android.launcher2.LauncherApplication这个路径下。
android:label:指定了桌面的名字是叫 Launcher,如果要改名字就改values文件夹的string.xml中的相应属性就可以了。
android:icon:指定了Laucher的图标,这个图标可以在应用程序管理器中看见。如果需要更改Laucher的图片,重新设置这个属性就可以了。
android:hardwareAccelerated:指定了整个应用程序是启用硬件加速的,这样整个应用程序的运行速度会更快。
android:largeHeap:指定了应用程序使用了大的堆内存,能在一定程度上避免,对内存out of memory错误的出现。可以在values文件夹的config.xml中看到对是否启用硬件加速和大内存的配置。如下:
true
false
2、LauncherApplication中onCreate()方法:
public class LauncherApplication extends Application {
public LauncherModel mModel;
public IconCache mIconCache;
private static boolean sIsScreenLarge;
private static float sScreenDensity;
WeakReference mLauncherProvider;
@Override
public void onCreate() {
super.onCreate();
// set sIsScreenXLarge and sScreenDensity *before* creating icon cache
final int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
sIsScreenLarge = screenSize == Configuration.SCREENLAYOUT_SIZE_LARGE ||