本文主要是介绍startActivity函数分析-(基于10.0.0)未完待续,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Activity类有2个startActivity 函数的重载形式
public void startActivity(Intent intent) {this.startActivity(intent, null);}public void startActivity(Intent intent, @Nullable Bundle options) {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);}}
可以看出内部还是调用了startActivityForResult 函数,传入的requestCode=-1,下来我们看看startActivityForResult函数
public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) {startActivityForResult(intent, requestCode, null);}public void startActivityForResult(@RequiresPermission Intent intent, int requestCode,@Nullable Bundle options) {if (mParent == null) {options = transferSpringboardActivityOptions(options);// 重点看这里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) {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);}}}
我们可以看出startActivityForResult中实际上是调用了Instrumentation类的execStartActivity函数,实际上startActivityFromChild内部也是调用了mInstrumentation.execStartActivity,那我们就重点分析下这个函数
这篇关于startActivity函数分析-(基于10.0.0)未完待续的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!