Android应用程序启动过程——Launcher源码分析
16lz
2021-01-24
当我们在Launcher界面单击一个应用程序图标时就会启动一个程序,那这一个过程究竟发生了些哪样呢?让我们跟踪Launcher源码来分析一下吧。
先上流程图:
step1、追踪Launcher 从源码中我们可以发现Launcher其实也是一个程序,它继承于Activity。找到该文件中的onCreate()方法,代码片段如下:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LauncherApplication app = ((LauncherApplication)getApplication()); mModel = app.setLauncher(this); mIconCache = app.getIconCache(); mDragController = new DragController(this); mInflater = getLayoutInflater(); mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); if (PROFILE_STARTUP) { android.os.Debug.startMethodTracing("/sdcard/launcher"); } loadHotseats(); checkForLocaleChange(); setWallpaperDimension(); setContentView(R.layout.launcher); setupViews(); registerContentObservers(); lockAllApps(); mSavedState = savedInstanceState; restoreState(mSavedState); if (PROFILE_STARTUP) { android.os.Debug.stopMethodTracing(); } if (!mRestoring) { mModel.startLoader(this, true); }
找到关键部分,也就是上面被标注红色代码。mModel是LauncherModel类型对象,接下来我们跟踪LauncerModel.java文件。
step2、 `LauncherModel是一个BroadcastReceiver,在这里我们先进入startLoader(Context context, boolean isLaunching) 方法。
LoaderTask实现了Runnable接口,接着我们再找到该实现类的run()方法,代码片段如下:
读取系统中各应用主Activity的信息代码片段如下:
step3、当我们单击应用程序图标时所执行的对应方法为Launcher.java里的onClick()方法,其代码如下:
到此就对应用程序的启动过程分析结束了,欢迎各位网友的指正和建议,以其共同进步。
更多相关文章
- 如何在多个LinearLayout中添加分隔线?
- [Android]滑动刷新ListView——android-pulltorefresh使用方法解
- android adb push 与 adb install 区别(两种安装APK的方法)
- Android(安卓)的Bitmap的修改方法
- 深入探讨 Android(安卓)传感器随处监控您的环境
- Android(安卓)实现文件的下载
- ANDROID应用安全防御
- Android(安卓)自定义View (三部曲)
- Service与Android系统设计(3)