Launcher里点击一个应用图标的内部流程分析

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/78013971
从Android手机屏幕上点击一个应用图标进行启动Activity的过程分析如下:

/packages/apps/Launcher3/src/com/android/launcher3/Launcher.java
public class Launcher extends Activity

Launcher # startActivitySafely()
@Thunk boolean startActivitySafely(View v, Intent intent, Object tag) { boolean success = false; if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); return false; } // ...关键代码 success = startActivity(v, intent, tag); } catch (ActivityNotFoundException e) { // 没有找到Activity Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); } return success; }

Launcher # startActivity()
private boolean startActivity(View v, Intent intent, Object tag) { // 添加flag intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // ... 省略代码try{ startActivity(intent, optsBundle); return true; } catch(){ } return false; }

【Launcher里点击一个应用图标的内部流程分析】下面的分析过程可参考 Activity具体是怎么创建的?又是怎么显示出来的?
Activity # startActivity()
@Override public void startActivity(Intent intent, @Nullable Bundle options) { if (options != null) { startActivityForResult(intent, -1, options); } else { startActivityForResult(intent, -1); } }

    推荐阅读