Activity创建流程

本文详细分析了Android应用中Activity的创建流程,从桌面图标点击开始,经过启动进程、ActivityThread,直至Activity的启动。重点讲解了ActivityThread的performLaunchActivity()方法,以及在attach方法中涉及的ActivityManagerService、H、ApplicationThread的角色。通过Instrumentation反射创建Activity,并调用onCreate()方法,从而开始布局的设置和绘制,为后续探讨Activity的绘制流程奠定了基础。
摘要由CSDN通过智能技术生成

Activity 创建流程分析

在前两篇文章中我们谈到了从桌面点击图标到启动进程以及启动ActivityThread再到ActivityThread启动Activity的过程分析
1. 安卓应用启动流程分析
2. ActivityThread启动页面分析

本片文章可谓是紧接着上面两篇文章,上文说到的ActivityThread performLaunchActivity(),今天继续讲从这里如何创建Activity 的。

 private void handleLaunchActivity(ActivityClientRecord r, Intent customIntent) {
   
     。。。
        if (r.profileFd != null) {
   
            mProfiler.setProfiler(r.profileFile, r.profileFd);
            mProfiler.startProfiling();
            mProfiler.autoStopProfiler = r.autoStopProfiler;
        }
        handleConfigurationChanged(null, null);
        //上节提到,我们ActivityThread开启来之后呢,开启Activity 的入口在这里,那么我们还是继续深入其中,看看他又做了什么操作。
        Activity a = performLaunchActivity(r, customIntent);

        if (a != null) {
   
            r.createdConfig = new Configuration(mConfiguration);
            Bundle oldState = r.state;
            handleResumeActivity(r.token, false, r.isForward);
            。。。
        } else {
   
            try {
   
                ActivityManagerNative.getDefault()
                   .finishActivity(r.token, Activity.RESULT_CANCELED, null);
            } catch (RemoteException ex) {
   
                // Ignore
            }
        }
    }
private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
   
        ActivityInfo aInfo = r.activityInfo;
        if (r.packageInfo == null) {
   
            r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo,
           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值