Android Activity的启动过程
Activity的启动过程真的很复杂,先看一张图大概了解一下,其中用灰色背景框起来的是在同一个类的方法,如下图:
那接下来就从源码的角度来分析Activity的启动过程。
当然是从Activity的startActivity方法开始的,
***@Override
public void startActivity(Intent intent) {
(intent, null);
}
使用this关键字调用了startActivity方法的两个参数的重载。如下:
***@Override
public void startActivity(Intent intent, ***@Nullable Bundle options) {
if (options != null) {
startActivityForResult(intent, -1, options);
} else {
// Note we want to go through this call patibility with
// applications that may have overridden the method.
startActivityForResult(intent, -1);
}
}
不管怎样,都会调用startActivityForResult方法。并将intent传进。
public void startActivityForResult(Intent intent, int requestCode) {
startActivityForResult(intent, requestCode, null);
}
转到了startActivityForResult三个参数的重载方法,那就跟进瞧瞧,源码如下:
public void startActivityForResult(Intent intent, int requestCode, ***@Nullable Bundle options) {
if (mParent == null) {
ar =
(
this, (), mToken, this,
intent, requestCode, options);
if (ar != null) {
(
mToken, mEmbeddedID, requestCode, (),
());
}
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) {
(this, intent, requestCode, options);
}
Android Activity的启动过程 来自淘豆网m.daumloan.com转载请标明出处.