转载请注明出处: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);
}
}
推荐阅读
- 从零开发一个完整的Android项目(九)——图片浏览
- Android开发|ViewPager自适应高度问题
- Android|Android 指定销毁一个Activity
- 【Android】简单图片浏览器
- 理解ButterKnife(自动生成绑定资源的代码)
- MAC下搭建Android Studio
- NestedScrollingParent 和NestedScrollingChild 实现嵌套滑动
- android用shape画一条横线
- 华为推送 的坑
- Duplicate class com.alipay.a.a.a found in modules classes.jar (:alipaySdk-15.6.2-20190416165036:) an