public ActivityResult execStartActivity( Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) { IApplicationThread whoThread = (IApplicationThread) contextThread; Uri referrer = target != null ? target.onProvideReferrer() : null; if (referrer != null) { intent.putExtra(Intent.EXTRA_REFERRER, referrer); } if (mActivityMonitors != null) { synchronized (mSync) { final int N = mActivityMonitors.size(); for (int i=0; i<N; i++) { final ActivityMonitor am = mActivityMonitors.get(i); if (am.match(who, null, intent)) { am.mHits++; if (am.isBlocking()) { return requestCode >= 0 ? am.getResult() : null; } break; } } } } try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(who); int result = ActivityManagerNative.getDefault()//2 .startActivity(whoThread, who.getBasePackageName(), intent, intent.resolveTypeIfNeeded(who.getContentResolver()), token, target != null ? target.mEmbeddedID : null, requestCode, 0, null, options); checkStartActivityResult(result, intent); } catch (RemoteException e) { throw new RuntimeException("Failure from system", e); } return null; }
我们看到,在注释1处和注释2处代码不一样,接下来继续看不同部分的代码,api26:
1 2 3 4 5 6 7 8 9 10 11 12 13
public static IActivityManager getService() { return IActivityManagerSingleton.get(); }
private static final Singleton<IActivityManager> IActivityManagerSingleton = new Singleton<IActivityManager>() { @Override protected IActivityManager create() { final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE); final IActivityManager am = IActivityManager.Stub.asInterface(b); return am; } };
api25:
1 2 3
static public IActivityManager getDefault() { return gDefault.get(); }
1 2 3 4 5 6 7 8 9 10 11 12 13
private static final Singleton<IActivityManager> gDefault = new Singleton<IActivityManager>() { protected IActivityManager create() { IBinder b = ServiceManager.getService("activity"); if (false) { Log.v("ActivityManager", "default service binder = " + b); } IActivityManager am = asInterface(b); if (false) { Log.v("ActivityManager", "default service = " + am); } return am; } };
/** * {@hide} * @deprecated will be removed soon. See individual methods for alternatives. //将会被移除 */ @Deprecated public abstract class ActivityManagerNative { /** * Cast a Binder object into an activity manager interface, generating * a proxy if needed. * * @deprecated use IActivityManager.Stub.asInterface instead. */ //这里说可以用IActivityManager.Stub.asInterface来代替,这个方法已不被鼓励使用 static public IActivityManager asInterface(IBinder obj) { return IActivityManager.Stub.asInterface(obj); }
/** * Retrieve the system's default/global activity manager. * * @deprecated use ActivityManager.getService instead. */ static public IActivityManager getDefault() { return ActivityManager.getService(); }
/** * Convenience for checking whether the system is ready. For internal use only. * * @deprecated use ActivityManagerInternal.isSystemReady instead. */ static public boolean isSystemReady() { return ActivityManager.isSystemReady(); }
/** * @deprecated use ActivityManager.broadcastStickyIntent instead. */ static public void broadcastStickyIntent(Intent intent, String permission, int userId) { broadcastStickyIntent(intent, permission, AppOpsManager.OP_NONE, userId); }
/** * Convenience for sending a sticky broadcast. For internal use only. * If you don't care about permission, use null. * * @deprecated use ActivityManager.broadcastStickyIntent instead. */ static public void broadcastStickyIntent(Intent intent, String permission, int appOp, int userId) { ActivityManager.broadcastStickyIntent(intent, appOp, userId); }
/** * @deprecated use ActivityManager.noteWakeupAlarm instead. */ static public void noteWakeupAlarm(PendingIntent ps, int sourceUid, String sourcePkg, String tag) { ActivityManager.noteWakeupAlarm(ps, sourceUid, sourcePkg, tag); }
/** * @deprecated use ActivityManager.noteAlarmStart instead. */ static public void noteAlarmStart(PendingIntent ps, int sourceUid, String tag) { ActivityManager.noteAlarmStart(ps, sourceUid, tag); }
/** * @deprecated use ActivityManager.noteAlarmFinish instead. */ static public void noteAlarmFinish(PendingIntent ps, int sourceUid, String tag) { ActivityManager.noteAlarmFinish(ps, sourceUid, tag); } }
“@deprecated will be removed soon. See individual methods for alternatives. “上面注释说明这个类将会被弃用,我们可以用ActivityManager来替代,而且ActivityManagerProxy已经被删除了。