Cloneable clone new Intent(this)
setAction COMPONENT_NAME addCategory addFlags
getIntent parseUri setData category identified launchFlags
package component schemas extra
getAction getData getScheme getType getCategories
getExtra
Activity
public boolean dispatchTouchEvent(MotionEvent ev) {
2739 if (ev.getAction() == MotionEvent.ACTION_DOWN) {
2740 onUserInteraction();
2741 }
2742 if (getWindow().superDispatchTouchEvent(ev)) {
2743 return true;
2744 }
2745 return onTouchEvent(ev);
2746 }
2747
PhoneWindow
superDispatchTouchEvent
@Override
1718 public boolean superDispatchTouchEvent(MotionEvent event) {
1719 return mDecor.superDispatchTouchEvent(event);
1720 }
mDecor = DecorView
private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {
public boolean superDispatchTouchEvent(MotionEvent event) {
2369 return super.dispatchTouchEvent(event);
2370 }
superDispatchTouchEvent
dispatchTouchEvent
ViewGroup
dispatchTouchEvent
Activity
startActivity
startActivityForResult
Instrumentation
executeStartActivity
ActivityManagerNative.startActivity
startActivityForResult
上面这个方法就是Intent获取到ActivityInfo的核心,它的大致过程如下:
首先获取Intent的Component对象,如果不为空,说明指定了Component,
那么就直接通过Component找到ActivityInfo列表,并且这个列表size为1,
所以这个ActivityInfo就是指定需要跳转的组件。
如果没有指定Component,那就是隐式Intent调用,
接着获取Intent传递的需要跳转的包名。
如果包名为空,则会通过ActivityIntentResolver等进行模糊匹配,
比如根据Action、Category等。
如果包名不为空,则直接根据包名来获取到对应的ActivityInfo对象,
而mActivities就是PMS存储的activity信息表。
// 获取Intent的Component对象
ComponentName comp = intent.getComponent();
if (comp == null) {
if (intent.getSelector() != null) {
intent = intent.getSelector();
comp = intent.getComponent();
}
}
// 不为空,是显式Intent,直接获取到ActivityInfo返回
if (comp != null) {
final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
final ActivityInfo ai = getActivityInfo(comp, flags, userId);
if (ai != null) {
final ResolveInfo ri = new ResolveInfo();
ri.activityInfo = ai;
list.add(ri);
}
return list;
}
// 为空,是隐式Intent
synchronized (mPackages) {
final String pkgName = intent.getPackage();
if (pkgName == null) {
// 代码省略
return result;
}
// 通过包名获取到Package对象
final PackageParser.Package pkg = mPackages.get(pkgName);
if (pkg != null) {
// 在获取到ActivityInfo对象
return filterIfNotSystemUser(
mActivities.queryIntentForPackage(
intent, resolvedType, flags, pkg.activities, userId),
userId);
}
return new ArrayList<ResolveInfo>();
}
}
PackageManagerService
queryIntentActivities
componentName
mPackages.get pkgName
PackageManager
ContextWraper
@Override
public PackageManager getPackageManager() {
return mBase.getPackageManager();
}
ActivityThread
getPackageManager
ServiceManager.getService
SystemServer SystemServer run
mSystemServiceManager = new SystemServiceManager(mSystemContext);
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
PackageManagerService main函数创建出来,并通过ServiceManager
addService