Android应用程序启动过程源代码分析
分类: Android 2011-08-19 00:58 5447人阅读评论(40) 收藏举报
前文简要介绍了Android应用程序的Activity的启动过程。在Android系统中,应用程序是由Activity组成的,因此,应用程序的启动过程实际上就是应用程序中的默认Activity的启动过程,本文将详细分析应用程序框架层的源代码,了解Android应用程序的启动过程。
在上一篇文章Android应用程序的Activity启动过程简要介绍和学习计划中,我们举例子说明了启动Android应用程序中的Activity的两种情景,其中,在手机屏幕中点击应用程序图标的情景就会引发Android应用程序中的默认Activity的启动,从而把应用程序启动起来。这种启动方式的特点是会启动一个新的进程来加载相应的Activity。这里,我们继续以这个例子为例来说明Android应用程序的启动过程,即MainActivity的启动过程。
MainActivity的启动过程如下图所示:
点击查看大图
下面详细分析每一步是如何实现的。
Step 1.
在Android系统中,应用程序是由Launcher启动起来的,其实,Launcher本身也是一个应用程序,其它的应用程序安装后,就会Launcher的界面上出现一个相应的图标,点击这个图标时,Launcher就会对应的应用程序启动起来。
Launcher的源代码工程在packages/apps/Launcher2目录下,/android/launcher2/:
view plaincopy to clipboardprint?
/**
* Default launcher application.
*/
public final class Launcher extends Activity
implements , OnLongClickListener, , {
......
/**
* Launches the intent referred by the clicked shortcut.
*
* ***@param v The view representing the clicked shortcut.
*/
public void onClick(View v) {
Object tag = ();
if (tag instanceof ShortcutInfo) {
// Open shortcut
final Intent intent = ((ShortcutInfo) tag).intent;
int[] pos = new int[2];
(pos);
(new Rect(pos[0], pos[1],
pos[0] + (), pos[1] + ()));
startActivitySafely(intent, tag);
} else if (tag instanceof FolderInfo) {
......
} else if (v == mHandleView) {
......
}
}
void startActivitySafely(Intent intent, Object tag) {
();
try {
start
Android应用程序启动过程源代码分析 来自淘豆网m.daumloan.com转载请标明出处.