点击桌面图标Activity启动流程分析 - 基于Android5.0源码

来源:互联网 发布:与泰国人聊天软件 编辑:程序博客网 时间:2024/05/29 03:21

Activity启动有两种方式:

1,通过点击桌面的图标来启动一个应用,进而会启动一个Activity。

2,直接在一个Activity或者Service中通过startActivity来启动一个Activity。第一种方式的本质也是在Launcher中调用startActivity方法。


先看看大致的流程图:



详细步骤如下:

1,点击桌面上的应用程序按钮,进入Launcher:onClick方法

2,通过Object tag = v.getTag()得倒当前点击的应用信息,判断tag属于哪一个实例(ShortcutInfo,FolderInfo, AppInfo,LauncherAppWidgetInfo),当前点击桌面的app,进入onClickAppShortcut

3,onClickAppShortcut--->startAppShortcutOrInfoActivity-->startActivitySafely->startActivity

4,startActivity中,intent可以看出action是:android.intent.action.MAIN,category是:android.intent.category.LAUNCHER, component是:com.example.test_service/.MainActivity(has extras),这几个参数是在App的AndroidManifest.xml配置的。然后调用Activity中的startActivity

5,在Activity的startActivity中最终会调用startActivityForResult

6,startActivityForResult中的核心代码:

if (mParent == null) {

            Instrumentation.ActivityResult ar =
               mInstrumentation.execStartActivity(
                   this, mMainThread.getApplicationThread(), mToken, this,
                   intent, requestCode, options);

              ......

}

mParent是当前Activity的父对象,如果没有父对象,执行execStartActivity,mInstrumentation是Activity的成员变量,用来监督和应用程序的交互。mMainThread是ActivityThread对象,mMainThread.getApplicationThread()得倒ApplicationThread实例。ApplicationThread继承自ApplicationThreadNative,是一个Binder对象。他的作用是:ActivityManagerService用它来和ActivityThread进行进程间的通信。

这里引出很重要的四个类:ActivityManagerService(AMS),ActivityTask,ActvityThread,ApplicationThread。AMS管理Actvity的生命周期;AMS将产生的Actvity实例压入ActivityTask;对于每一个应用程序来说都有一个主进程ActivityThread;ApplicationThread是ActivityThread的内部类,每一个ActivityThread都有一个ApplicationThread对象,它是Binder对象,负责和其他进程的通信。

mToken是IBinder对象的远程接口。

7,Instrumentation的方法execStartActivity中:

int result = ActivityManagerNative.getDefault()

                .startActivity(whoThread,who.getBasePackageName(), intent,

                       intent.resolveTypeIfNeeded(who.getContentResolver()),

                       token, target != null ? target.mEmbeddedID : null,

                       requestCode, 0, null, options);

ActivityManagerNative.getDefault()返回的是ActivityManagerService的远程IActivityManager接口即AMS,然后调用ActivityManagerService的方法startActivity。

8,在AMS的startActivityAsUser中会去调用StackSupervisor的方法startActivityMayWait

9,StackSupervisor中的resolveActivity方法解析intent的内容,得倒Activity的相关信息,并保存在aInfo中。

ActivityInfo aInfo = resolveActivity(intent, resolvedType,startFlags,

               profilerInfo, userId);

接下来调用方法startActivityLocked

10,final intstartActivityLocked(IApplicationThread caller,

            Intentintent, String resolvedType, ActivityInfo aInfo,

            IVoiceInteractionSession voiceSession,IVoiceInteractor voiceInteractor,

            IBinderresultTo, String resultWho, int requestCode,

            intcallingPid, int callingUid, String callingPackage,

            intrealCallingPid, int realCallingUid, int startFlags, Bundle options,

            booleancomponentSpecified, ActivityRecord[] outActivity, ActivityContainer container,

            TaskRecordinTask){

                ……

ProcessRecord callerApp = null;

        if (caller != null) {

            callerApp =mService.getRecordForAppLocked(caller);

            if (callerApp != null) {

                callingPid = callerApp.pid;

                callingUid =callerApp.info.uid;

            }

        }

……

}

传进来的参数caller(android.app.ApplicationThreadProxy@135d87f)是调用者进程的信息,这里是Launcer应用进程,LauncherLauncher应用进程的信息保存在callerApp(AppProcessRecord{1d1e104c10090:com.motorola.motolauncher/u0a32})中。resultTo保存的是Launcher这个activity里的一个Binder对象,通过它可以获得Launcher 中的Activity的信息。接下来创建即将要启动的Activity的相关信息,并保存在r变量中:

ActivityRecord r = new ActivityRecord(mService, callerApp,callingUid, callingPackage,

               intent, resolvedType, aInfo, mService.mConfiguration, resultRecord,resultWho,

               requestCode, componentSpecified, this, container, options);

接着调用startActivityUncheckedLocked函数进行下一步操作。

11,startActivityUncheckedLocked中先得倒Activity的启动模式(launchSingleTop,launchSingleInstance,launchSingleTask),因为本例子中的启动模式是standar,所以会去创建一个新的task来启动Activit,启动Activity:targetStack.startActivityLocked(r,newTask, doResume, keepCurTransition, options)。

if (((launchFlags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0&&

               (launchFlags & Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0)

                ||launchSingleInstance || launchSingleTask) {

            // Ifbring to front is requested, and no result is requested and we have not

            // beengiven an explicit task to launch in to, and

            // we canfind a task that was started with this same

            //component, then instead of launching bring that one to the front.

            if (inTask== null && r.resultTo == null) {

                // Seeif there is a task to bring to the front. If this is

                // aSINGLE_INSTANCE activity, there can be one and only one

                //instance of it in the history, and it is always in its own

                //unique task, so we do a special search.

               ActivityRecord intentActivity = !launchSingleInstance ?

                       findTaskLocked(r) : findActivityLocked(intent, r.info);

                ….

这里在查询是否是singleInstance的Activity,findActivityLocked查询的结果不存在,返回null。接下来调用targetStack.resumeTopActivityLocked(null,options):

if (doResume) {

                           targetStack.resumeTopActivityLocked(null, options);

                           if (!movedToFront) {

                                // Make sure tonotify Keyguard as well if we are not running an app

                                // transitionlater.

                               notifyActivityDrawnForKeyguard();

                           }

                       }

……

12,进入到ActivityStack的resumeTopActivityLocked中,调用resumeTopActivityInnerLocked,mResumedActivity保存的是Launcer,然后调用startPausingLocked

13,startPausingLocked中,将mResumedActivity即当前的LauncherActivity保存在prev中,有以下代码:

if (prev.app != null && prev.app.thread != null) {

            if (DEBUG_PAUSE) Slog.v(TAG,"Enqueueing pending pause: " + prev);

            try {

               EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY,

                       prev.userId, System.identityHashCode(prev),

                       prev.shortComponentName);

               mService.updateUsageStats(prev, false);

               prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing,

                       userLeaving, prev.configChangeFlags, dontWait);

 

                //BEGIN Motorola, w21932, 03/19/2013, IKJBXLINE-945 / Port IKHALFMWK-457

               notifyEventLog("am_pause_activity",

                              System.identityHashCode(prev),

                               null,

                               prev.shortComponentName,

                               null);

                // ENDIKJBXLINE-945

            }

prev.app表示Launcher的application,prev.app.thread表示Launcher进程,通过调用prev.app.thread.schedulePauseActivity通知Launcher进程中的Launcher Activity要pause了。Prev.app.thread是一个ApplicationThread对象的远程接口对象的方法schedulePauseActivity,通过调用这个远程接口来通知Launcher进程这个Activity要pause了。

14,ApplicationThreadNative的方法schedulePauseActivity:

public final void schedulePauseActivity(IBinder token,boolean finished,

            booleanuserLeaving, int configChanges, boolean dontReport) throws RemoteException {

        // BEGINMotorola, atzakis, 03/18/2013, IKJBXLINE-749

       Kpi6paTop.log(Kpi6paTop.Tag.AMS2, token);

        // ENDIKJBXLINE-749

        Parcel data =Parcel.obtain();

       data.writeInterfaceToken(IApplicationThread.descriptor);

       data.writeStrongBinder(token);

        data.writeInt(finished? 1 : 0);

       data.writeInt(userLeaving ? 1 :0);

       data.writeInt(configChanges);

       data.writeInt(dontReport ? 1 : 0);

       mRemote.transact(SCHEDULE_PAUSE_ACTIVITY_TRANSACTION, data, null,

               IBinder.FLAG_ONEWAY);

       data.recycle();

}

mRemote是一个远程IBinder对象,通过Binder进程间通信机制进入ApplicationThread的schedulePauseActivity,ApplicationThread是ActivityThread的一个内部类

15,ApplicationThread中

public final voidschedulePauseActivity(IBinder token, boolean finished,

                boolean userLeaving, intconfigChanges, boolean dontReport) {

            // BEGIN Motorola, ajk037,04/11/2013, IKJBXLINE-4547

            Kpi6paTop.log(Kpi6paTop.Tag.AT1,token);

            // END IKJBXLINE-4547

            Log.d(TAG, "karl schedulePauseActivity");

            sendMessage(

                    finished ?H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY,

                    token,

                    (userLeaving ? 1 : 0) |(dontReport ? 2 : 0),

                    configChanges);

        }

这里fnished是false,通过Handler的PAUSE_ACTIVITY,token表示Launcher的远程进程。

16,public voidhandleMessage(Message msg) {

…..

switch (msg.what) {

…….

case PAUSE_ACTIVITY:

                   Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER,"activityPause");

                    handlePauseActivity((IBinder)msg.obj,false, (msg.arg1&1) != 0, msg.arg2,

                           (msg.arg1&2) != 0);

                   maybeSnapshot();

                   Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);

                    break;

这里(IBinder)msg.obj表示的是Launcher进程中的Activity,handlePauseActivity这个函数是ActivityThread的函数

17,

private void handlePauseActivity(IBinder token, booleanfinished,

            booleanuserLeaving, int configChanges, boolean dontReport) {

       ActivityClientRecord r = mActivities.get(token);

        if (r != null){

            // BEGINMotorola, ajk037, 04/11/2013, IKJBXLINE-4547

           Kpi6paTop.log(Kpi6paTop.Tag.AT2, r.activityInfo);

            // ENDIKJBXLINE-4547

           //Slog.v(TAG, "userLeaving=" + userLeaving + " handlingpause of " + r);

            if(userLeaving) {

               performUserLeavingActivity(r);

            }

 

           r.activity.mConfigChangeFlags |= configChanges;

           performPauseActivity(token, finished, r.isPreHoneycomb());

 

            // Makesure any pending writes are now committed.

            if(r.isPreHoneycomb()) {

               QueuedWork.waitToFinish();

            }

 

            // Tellthe activity manager we have paused.

            if(!dontReport) {

                try {

                   ActivityManagerNative.getDefault().activityPaused(token);

                }catch (RemoteException ex) {

                }

            }

           mSomeActivitiesChanged = true;

        }

}

这个函数做了三件事:1,performPauseActivity告知用户要离开Activity了;2,通过performPauseActivity来pause token的Launcher Activity,这就印证了在一个activity 启动另一个activity的时候会先执行当前activity的onPause方法,然后执行另一个activity的onCreate,onStart,onResume;3,ActivityManagerNative.getDefault().activityPaused(token);来告知AMS当前这个Activity要pause了。

18,activityPaused这个函数在ActivityManagerProxy类中,它是ActivityManagerNative的一个内部类。

class ActivityManagerProxyimplements IActivityManager{

……

public void activityPaused(IBindertoken) throws RemoteException

   {

        Parcel data = Parcel.obtain();

        Parcel reply = Parcel.obtain();

       data.writeInterfaceToken(IActivityManager.descriptor);

        data.writeStrongBinder(token);

       mRemote.transact(ACTIVITY_PAUSED_TRANSACTION, data, reply, 0);

        reply.readException();

        data.recycle();

        reply.recycle();

   }

……

}

通过Binde进程间通信机制调用到ActivityManagerService中的activityPaused中去。

19,activityPaused函数中执行ActivityStack stack =ActivityRecord.getStackLocked(token);

stack.activityPausedLocked(token,false);

再次进入到ActivityStack的activityPausedLocked方法中。

20,/frameworks/base/services/core/java/com/android/server/am/ActivityStack.java中

final voidactivityPausedLocked(IBinder token, boolean timeout) {

        if (DEBUG_PAUSE) Slog.v(

            TAG, "Activity paused:token=" + token + ", timeout=" + timeout);

 

        final ActivityRecord r =isInStackLocked(token);

        if (r != null) {

           mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);

            if (mPausingActivity == r) {

                if (DEBUG_STATES) Slog.v(TAG,"Moving to PAUSED: " + r

                        + (timeout ? "(due to timeout)" : " (pause complete)"));

                completePauseLocked(true);

                // BEGIN Motorola, ajk037,04/11/2013, IKJBXLINE-4547

               Kpi6paTop.log(Kpi6paTop.Tag.AMS103, r.realActivity);

                // END IKJBXLINE-4547

            } else {

               EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE,

                        r.userId,System.identityHashCode(r), r.shortComponentName,

                        mPausingActivity !=null

                            ?mPausingActivity.shortComponentName : "(none)");

            }

        }

   }

这里mPausingActivity== r为true,执行方法completePauseLocked

21,ActivityStack中:

private voidcompletePauseLocked(boolean resumeNext) {

            ActivityRecordprev = mPausingActivity;

            ……

            if(prev != null) {

                            ……

                            mPausingActivity= null;

}

if (resumeNext) {

                ……

if (!mService.isSleepingOrShuttingDown()){

       mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null);

 }

……

}

}

mPausingActivity被清空,不再需要他,然后调用resumeTopActivitiesLockedà resumeTopActivityInnerLocked à startSpecificActivityLocked

22ActivityStackSupervisor.startSpecificActivityLocked

void startSpecificActivityLocked(ActivityRecord r,

            booleanandResume, boolean checkConfig) {

        // Is thisactivity's application already running?

        ProcessRecordapp = mService.getProcessRecordLocked(r.processName,

               r.info.applicationInfo.uid, true);

r.task.stack.setLaunchTime(r);

 

        // BEGINMotorola, ajk037, 04/11/2013, IKJBXLINE-4547

       Kpi6paTop.log(Kpi6paTop.Tag.AMS7, r.processName, r.realActivity);

        // END IKJBXLINE-4547

 

        if (app !=null && app.thread != null) {

            try {

                if((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0

                       || !"android".equals(r.info.packageName)) {

                    //Don't add this if it is a platform component that is marked

                    //to run in multiple processes, because this is actually

                    //part of the framework so doesn't make sense to track as a

                    //separate apk in the process.

                   app.addPackage(r.info.packageName, r.info.applicationInfo.versionCode,

                           mService.mProcessStats);

                }

               realStartActivityLocked(r, app, andResume, checkConfig);

                return;

            } catch(RemoteException e) {

               Slog.w(TAG, "Exception when starting activity "

                       + r.intent.getComponent().flattenToShortString(), e);

            }

 

            // If adead object exception was thrown -- fall through to

            // restartthe application.

        }

mService.startProcessLocked(r.processName,r.info.applicationInfo, true, 0,

               "activity", r.intent.getComponent(), false, false, true);

}

先根据processName和application的uid得倒activity的application,因为第一次启动,这是app为null,然后启动ActivityManagerService的startProcessLocked,再次检查process+uid的application是否存在,如果不能存在,创建新的app=newProcessRecordLocked(info, processName,isolated, isolatedUid);

然后startProcessLocked(

                app, hostingType, hostingNameStr,abiOverride, entryPoint, entryPointArgs);

23,      AMS的startProcessLocked:

private final void startProcessLocked(ProcessRecord app,String hostingType,

            StringhostingNameStr, String abiOverride, String entryPoint, String[] entryPointArgs){

……

Process.ProcessStartResult startResult =Process.start(entryPoint,

                   app.processName, uid, uid, gids, debugFlags, mountExternal,

                   app.info.targetSdkVersion, app.info.seinfo, requiredAbi, instructionSet,

                   app.info.dataDir, entryPointArgs);

……

}

调用Process.start方法创建一个新的进程,在新进程中会导入ActivityThread类,并执行他的main方法。

frameworks\base\core\java\android\app\ActivityThread.java:

public static void main(String[] args) {

SamplingProfilerIntegration.start();

                CloseGuard.setEnabled(false);

 

       Environment.initForCurrentUser();

 

        // Set thereporter for event logging in libcore

       EventLogger.setReporter(new EventLoggingReporter());

 

       Security.addProvider(new AndroidKeyStoreProvider());

 

        // Make sureTrustedCertificateStore looks in the right place for CA certificates

        final FileconfigDir = Environment.getUserConfigDirectory(UserHandle.myUserId());

       TrustedCertificateStore.setDefaultUserDirectory(configDir);

 

       Process.setArgV0("<pre-initialized>");

 

       Looper.prepareMainLooper();

 

        ActivityThreadthread = new ActivityThread();

       thread.attach(false);

 

        if(sMainThreadHandler == null) {

            sMainThreadHandler= thread.getHandler();

        }

 

        if (false) {

           Looper.myLooper().setMessageLogging(new

                   LogPrinter(Log.DEBUG, "ActivityThread"));

        }

 

        Looper.loop();

 

        throw newRuntimeException("Main thread loop unexpectedly exited");

}

在main方法里面生成ActivityThread对象,然后调用attach方法,并进入消息循环,直到最后退出程序。

24,private void attach(booleansystem) {

       sCurrentActivityThread = this;

        mSystemThread= system; 

   ……

                                        UserHandle.myUserId());

           RuntimeInit.setApplicationObject(mAppThread.asBinder());

            final IActivityManager mgr =ActivityManagerNative.getDefault();

            try {

               mgr.attachApplication(mAppThread);

            } catch (RemoteException ex) {

                // Ignore

            }

  ……

}

调用ActivityManagerNative的函数attachApplication,传入ApplicationThread用来进行进程间通信用的。

25,ActivityManagerNative的attachApplication:

public void attachApplication(IApplicationThread app) throwsRemoteException

    {

       Log.d("ActivityManagerNative", "karl attachApplication:" + app);

        // BEGINMotorola, atzakis, 03/18/2013, IKJBXLINE-749

       Kpi6paTop.log(Kpi6paTop.Tag.AT4);

        // ENDIKJBXLINE-749

        Parcel data =Parcel.obtain();

        Parcel reply =Parcel.obtain();

       data.writeInterfaceToken(IActivityManager.descriptor);

       data.writeStrongBinder(app.asBinder());

       mRemote.transact(ATTACH_APPLICATION_TRANSACTION, data, reply, 0);

        reply.readException();

       data.recycle();

       reply.recycle();

}

通过Binder对象mRemote的方法transact进程间通信,进入AMS的attachApplication方法。

26,ActivityManagerService的attachApplication:

@Override

    public final voidattachApplication(IApplicationThread thread) {

        // BEGINMotorola, ajk037, 04/11/2013, IKJBXLINE-4547

       Kpi6paTop.log(Kpi6paTop.Tag.AMS4);

        // ENDIKJBXLINE-4547

 

        synchronized(this) {

            intcallingPid = Binder.getCallingPid();

            final longorigId = Binder.clearCallingIdentity();

           attachApplicationLocked(thread, callingPid);

           Binder.restoreCallingIdentity(origId);

        }

}

这里调用AMS的attachApplicationLocked。

27,ActivityManagerService的attachApplicationLocked:

private final booleanattachApplicationLocked(IApplicationThread thread,

            int pid) {

            ……

            //See if the top visible activity is waiting to run in this process...

        if (normalMode) {

            try {

                if(mStackSupervisor.attachApplicationLocked(app)) {

                    didSomething = true;

                }

            } catch (Exception e) {

                Slog.wtf(TAG, "Exceptionthrown launching activities in " + app, e);

                badApp = true;

            }

        }

            ……

}

调用ActivityStackSupervisor的attachApplicationLocked方法。然后再调用realStartActivityLocked,在realStartActivityLocked中调用:

app.thread.scheduleLaunchActivity(newIntent(r.intent), r.appToken,

                    System.identityHashCode(r),r.info, new Configuration(mService.mConfiguration),

                    r.compat,r.launchedFromPackage, r.task.voiceInteractor, app.repProcState,

                    r.icicle,r.persistentState, results, newIntents, !andResume,

                   mService.isNextTransitionForward(), profilerInfo);

进入到ActivityThread类的scheduleLaunchActivity中:

public final voidscheduleLaunchActivity(Intent intent, IBinder token, int ident,

                ActivityInfo info,Configuration curConfig, CompatibilityInfo compatInfo,

                String referrer, IVoiceInteractorvoiceInteractor, int procState, Bundle state,

                PersistableBundlepersistentState, List<ResultInfo> pendingResults,

                List<ReferrerIntent>pendingNewIntents, boolean notResumed, boolean isForward,

                ProfilerInfo profilerInfo) {

            ActivityClientRecordr = new ActivityClientRecord();

 

            r.token = token;

            r.ident = ident;

            r.intent = intent;

            r.referrer = referrer;

            r.voiceInteractor =voiceInteractor;

            r.activityInfo = info;

            r.compatInfo = compatInfo;

            r.state = state;

            r.persistentState =persistentState;

 

            r.pendingResults = pendingResults;

            r.pendingIntents =pendingNewIntents;

 

            r.startsNotResumed = notResumed;

            r.isForward = isForward;

 

            r.profilerInfo = profilerInfo;

 

           updatePendingConfiguration(curConfig);

 

            sendMessage(H.LAUNCH_ACTIVITY, r);

}

实例化一个ActivityClientRecord对象,然后初始化。通过Handler的sendMessage(H.LAUNCH_ACTIVITY,r); 调用handleLaunchActivity(r, null);

28,ActivityThread的handleLaunchActivity:

private voidhandleLaunchActivity(ActivityClientRecord r, Intent customIntent) {

            ……

            //Initialize before creating the activity

            WindowManagerGlobal.initialize();

            Activitya = performLaunchActivity(r, customIntent);

if (a != null) {

                ……

handleResumeActivity(r.token,false, r.isForward,

                    !r.activity.mFinished&& !r.startsNotResumed);

                ……

}

            ……

}

通过performLaunchActivity加载activity的类,然后create activity:

 

java.lang.ClassLoader cl =r.packageInfo.getClassLoader();

activity =mInstrumentation.newActivity(

                    cl,component.getClassName(), r.intent); activity = mInstrumentation.newActivity(

                    cl, component.getClassName(),r.intent);

activity =mInstrumentation.newActivity(

                    cl,component.getClassName(), r.intent);

           StrictMode.incrementExpectedActivityCount(activity.getClass());

 

……

if (r.isPersistable()) {

 

                    mInstrumentation.callActivityOnCreate(activity,r.state, r.persistentState);

                } else {

                   mInstrumentation.callActivityOnCreate(activity, r.state);

                }

 

29 在Instumentation的callActivityOnCreate中:

public void callActivityOnCreate(Activityactivity, Bundle icicle) {

        prePerformCreate(activity);

        activity.performCreate(icicle);

        postPerformCreate(activity);

   }

会调用actvity的onCreate方法,从28和29可知,加载完Activity后会执行onCreate和onResume。

Instrumentation中:

public voidcallActivityOnResume(Activity activity) {

        activity.mResumed = true;

        activity.onResume();

       

        if (mActivityMonitors != null) {

            synchronized (mSync) {

                final int N =mActivityMonitors.size();

                for (int i=0; i<N; i++) {

                    final ActivityMonitor am =mActivityMonitors.get(i);

                    am.match(activity,activity, activity.getIntent());

                }

            }

        }

   }

30,ActivityThread的performLaunchActivity中

private ActivityperformLaunchActivity(ActivityClientRecord r, Intent customIntent) {

            ……

Activity activity = null;

activity =mInstrumentation.newActivity(

                    cl,component.getClassName(), r.intent);

……

Application app =r.packageInfo.makeApplication(false, mInstrumentation);

……

Context appContext =createBaseContextForActivity(r, activity);

                CharSequence title =r.activityInfo.loadLabel(appContext.getPackageManager());

                Configuration config = newConfiguration(mCompatConfiguration);

……

}

先得倒要启动activity的信息,主要是getPackageInfo和Component信息r.intent.getComponent()。然后得倒application对象,根据AndroidManifest.xml的application标签的内容来生成。后面生成context对象Activity的上下文信息,并将这些信息attach到Activity中去。

31,然后调用Instrumentation的callActivityOnCreate,创建Activity,即会调用onCreate函数,Instrumenttation监督用户和activity的交互,相当于是系统运行的日志。


0 0