Android 四大组件-Activity

基于Android 4.4,分析Activity启动流程. 跟着邓凡平GitYuan走一遍4.4流程。

##一、概述
startActivity流程在4.4增加了ActivitySupervisor,涉及stack,task`以及UI内容Activity生命周期更为丰富。Activity启动发起后,通过Binder最终交由system进程中的AMS来完成,则启动流程如下图:
这里写图片描述

二、启动流程

###2.1 Activity.startActivity()

if (options != null) {
	startActivityForResult(intent, -1, options);
} else {
    // Note we want to go through this call for compatibility with
    // applications that may have overridden the method.
    startActivityForResult(intent, -1);
}

public void startActivityForResult(Intent intent, int requestCode) {
 startActivityForResult(intent, requestCode, null);
}
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
if (mParent == null) {
Instrumentation.ActivityResult ar =
    mInstrumentation.execStartActivity(
        this, mMainThread.getApplicationThread(), mToken, this,
        intent, requestCode, options);
if (ar != null) {
    mMainThread.sendActivityResult(
        mToken, mEmbeddedID, requestCode, ar.getResultCode(),
        ar.getResultData());
}
if (requestCode >= 0) {
    // If this start is requesting a result, we can avoid making
    // the activity visible until the result is received.  Setting
    // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the
    // activity hidden during this time, to avoid flickering.
    // This can only be done when a result is requested because
    // that guarantees we will get information back when the
    // activity is finished, no matter what happens to it.
    mStartedActivity = true;
}

final View decor = mWindow != null ? mWindow.peekDecorView() : null;
if (decor != null) {
    decor.cancelPendingInputEvents();
}
// TODO Consider clearing/flushing other event sources and events for child windows.
} else {
if (options != null) {
    mParent.startActivityFromChild(this, intent, requestCode, options);
} else {
    // Note we want to go through this method for compatibility with
    // existing applications that may have overridden it.
    mParent.startActivityFromChild(this, intent, requestCode);
	}
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值