startActivityForResult源码分析

来源:互联网 发布:热敏标签打印软件 编辑:程序博客网 时间:2024/04/30 02:13

直接上源码,不废话。

@Overridepublic void startActivityForResult(Intent intent, int requestCode) {    // If this was started from a Fragment we've already checked the upper 16 bits were not in    // use, and then repurposed them for the Fragment's index.    if (!mStartedActivityFromFragment) {        if (requestCode != -1 && (requestCode&0xffff0000) != 0) {            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");        }    }    super.startActivityForResult(intent, requestCode);}
没啥,首先判断是否是从Fragment发起的,最后一句继续跟踪。

public void startActivityForResult(Intent intent, int requestCode, @Nullable 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;        }        cancelInputsAndStartExitTransition(options);        // 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);        }    }}
首先判断有没有parentactivity,这个就是主要是处理tabactivity的情况,咱现在只看parent==null的情况。

第一句:  Instrumentation.ActivityResult ar =    mInstrumentation.execStartActivity(        this, mMainThread.getApplicationThread(), mToken, this,        intent, requestCode, options);
这里面所有问题我会发时间一一搞明白,时间就会比较拖延了,未完待续。



0 0
原创粉丝点击