2011-9-27 22:05:52

来源:互联网 发布:网线长度测试软件 编辑:程序博客网 时间:2024/04/26 04:08
 


2011-9-27 22:05:52


 Step 4. Instrumentation.execStartActivity
         这个函数定义在frameworks/base/core/java/android/app/Instrumentation.java文件中:


public class Instrumentation {

 ......

 public ActivityResult execStartActivity(
 Context who, IBinder contextThread, IBinder token, Activity target,
 Intent intent, int requestCode) {
  IApplicationThread whoThread = (IApplicationThread) contextThread;
  if (mActivityMonitors != null) {
   ......
  }
  try {
   int result = ActivityManagerNative.getDefault()
    .startActivity(whoThread, intent,
    intent.resolveTypeIfNeeded(who.getContentResolver()),
    null, 0, token, target != null ? target.mEmbeddedID : null,
    requestCode, false, false);
   ......
  } catch (RemoteException e) {
  }
  return null;
 }

 ......

}         这里的ActivityManagerNative.getDefault返回ActivityManagerService的远程接口,即ActivityManagerProxy接口,

具体可以参考Android系统在新进程中启动自定义服务过程(startService)的原理分析一文。

         这里的intent.resolveTypeIfNeeded返回这个intent的MIME类型,在这个例子中,没有AndroidManifest.xml设置MainActivity的MIME类型,因此,这里返回null。

         这里的target不为null,但是target.mEmbddedID为null,我们不用关注。