简单的描述Activity启动过程

1.ActivityThread
/**
 * This manages the execution of the main thread in an
 * application process, scheduling and executing activities,
 * broadcasts, and other operations on it as the activity
 * manager requests.
 *
 * {@hide}
 */
 framework的源码对ActivityThread的解释,主要是说在应用进程的主线程中管理执行工作,
 例如Activity和广播的调度工作及activity管理者的请求处理吧。


 2.Instrumentation
 /**
 * Base class for implementing application instrumentation code.  When running
 * with instrumentation turned on, this class will be instantiated for you
 * before any of the application code, allowing you to monitor all of the
 * interaction the system has with the application.  An Instrumentation
 * implementation is described to the system through an AndroidManifest.xml's
 * <instrumentation> tag.
 */
An Instrumentation implementation is described to the system through an AndroidManifest.xml's 
大概意思是说 这个仪表是通过AndroidMaifest.xml's的配置来向系统描述这个应用,
比如有哪些Activity,Service注册了等。


这里我是想简单描述Activity的启动步骤
1、startActivity()后会执行ActivityThread中的 performLaunchActivity(ActivityClientRecord r, Intent customIntent),
2、该方法中的Instrumentation的实例执行newActivity(ClassLoader cl, String className,Intent intent)方法,
3、方法中主要是执行(Activity)cl.loadClass(className).newInstance()生成Activity,如果在AndroidMenifest.xml中没有
 注册应该就会报异常。生成Activity实例后就调用attach()方法,根据Activity的一些信息创建PhoneWindow,WindowManger;接着接续在 performLaunchActivity方法中执行mInstrumentation.callActivityOnCreate(activity, r.state),也就是Activity回调oncreate方法,接着Activity就执行setContentView(),其实就是window调用setContentView(int),及初始化actionbar,这个window实际上是PhoneWindow实例。表层的启动过程大概就是这样吧,当然这里没有涉及binder通信机制。


#这里提到了Instrumentation 类其实是因为Android插件化开发涉及过。就是通过Instrumentation执行欺骗ActivityManagerService。


            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值