Android应用程序(activity)启动过程(一)

参考文章 Android应用程序启动过程源代码分析
本文基于 API 26 AS 3.0
主要讲栈顶activity的 onPause,onStop,onDestory

  1. startActivity() ——> startActivityForResult()
  2. 在 startActivityForResult()方法中调用 Instrumentation类中的 public ActivityResult execStartActivity()方法,这个方法加上了{@hide}对外是不可见的,前两步比较简单,很容易看懂
execStartActivity方法传递的几个参数: this,为启动Activity的对象;
contextThread,为Binder对象,是主进程的context对象;
token,也是一个Binder对象,指向了服务端一个ActivityRecord对象;
target,为启动的Activity; intent,启动的Intent对象;
requestCode,请求码; options,参数;
  1. 在 execStartActivity() 中调用了ActivityManager.getService().startActivity()
int result = ActivityManager.getService()
                .startActivity(whoThread, who.getBasePackageName(), intent,
                        intent.resolveTypeIfNeeded(who.getContentResolver()),
                        token, target != null ? target.mEmbeddedID : null,
                        requestCode, 0, null, options);
    public static IActivityManager getService() {
        return IActivityManagerSingleton.get();
    }

    private static final Singleton IActivityManagerSingleton =
            new Singleton() {
                @Override
                protected IActivityManager create() {
                    final IBinder b = ServiceManager.getService(Context.ACTIVITY_SERVICE);
                    // asInterface() 这里返回的其实就是Stub抽象类中的Proxy代理类
                    final IActivityManager am = IActivityManager.Stub.asInterface(b);
                    return am;
                }
            };
public abstract class Singleton {
    private T mInstance;

    protected abstract T create();

    public final T get() {
        synchronized (this) {
            if (mInstance == null) {
                mInstance = create();
            }
            return mInstance;
        }
    }
}

在一个单例中 通过IPC 获得远端服务的IActivityManager接口,实际实现就是一个运行在客户端的Proxy代理类 。(个人理解:IActivityManager.aidl文件,编译成java文件后内部生成一个Proxy代理类并且实现 IActivityManager )
地址:platform_frameworks_base/blob/master/core/java/android/app/IActivityManager.aidl
通过Proxy代理类重写其中的startActivity()方法:
其中的in、out、inout 代表只能写入、读出、既能读又能写

    int startActivity(in IApplicationThread caller, in String callingPackage, in Intent intent,
            in String resolvedType, in IBinder resultTo, in String resultWho, int requestCode,
            int flags, in ProfilerInfo profilerInfo, in Bundle options);

最后通过mRemote.transact 将客户端消息发送给远端服务 第一次进程间通信

  1. 远端服务层

platform_frameworks_base/master/services/core/java/com/android/server/am/ActivityManagerService.java

public class ActivityManagerService extends IActivityManager.Stub
        implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
  1. 从Proxy类的mRemote.transact()传递过来的参数,被传递到ActivityManagerService类的onTransact()方法来处理
 @Override
    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
            throws RemoteException {
        if (code == SYSPROPS_TRANSACTION) {
            // We need to tell all apps about the system property change.
            ArrayList procs = new ArrayList();
            synchronized(this) {
                final int NP = mProcessNames.getMap().size();
                for (int ip=0; ip apps = mProcessNames.getMap().valueAt(ip);
                    final int NA = apps.size();
                    for (int ia=0; ia

最后还是要通过 return super.onTransact(code, data, reply, flags); Stub抽象类的onTransact方法来处理,猜测:在父类中调用startActivity(),然后在子类中Override,因为我找不到Proxy这个代理类的地址,所以贴不了代码

  1. 然后我在 ActivityManagerService 中找到重写的startActivity方法
@Override
    public final int startActivity(IApplicationThread caller, String callingPackage,
            Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,
            int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) {
        return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo,
                resultWho, requestCode, startFlags, profilerInfo, bOptions,
                UserHandle.getCallingUserId());
    }
  1. 进而又调用了 startActivityAsUser,API 28 这里用了链式编程,最后执行execute(),一样的效果
@Override
    public final int startActivityAsUser(IApplicationThread caller, String callingPackage,
            Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,
            int startFlags, ProfilerInfo profilerInfo, Bundle bOptions, int userId) {
        enforceNotIsolatedCaller("startActivity");
        userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
                userId, false, ALLOW_FULL_ONLY, "startActivity", null);
        // TODO: Switch to user app stacks here.
        return mActivityStarter.startActivityMayWait(caller, -1, callingPackage, intent,
                resolvedType, null, null, resultTo, resultWho, requestCode, startFlags,
                profilerInfo, null, null, bOptions, false, userId, null, null,
                "startActivityAsUser");
  1. 在startActivityAsUser 进入 ActivityStarter类的startActivityMayWait()方法,哇哦,一坨…
    我看最后return 的res 是在startActivityLocked()方法中获得
int res = startActivityLocked(caller, intent, ephemeralIntent, resolvedType,
                    aInfo, rInfo, voiceSession, voiceInteractor,
                    resultTo, resultWho, requestCode, callingPid,
                    callingUid, callingPackage, realCallingPid, realCallingUid, startFlags,
                    options, ignoreTargetSecurity, componentSpecified, outRecord, container,
                    inTask, reason);
  1. 接着 ActivityStarter中startActivityLocked(),又调用了当前类中的startActivity
mLastStartActivityResult = startActivity(caller, intent, ephemeralIntent, resolvedType,
                aInfo, rInfo, voiceSession, voiceInteractor, resultTo, resultWho, requestCode,
                callingPid, callingUid, callingPackage, realCallingPid, realCallingUid, startFlags,
                options, ignoreTargetSecurity, componentSpecified, mLastStartActivityRecord,
                container, inTask);
  1. 点进去,surprise!又是N行,最最最后… ,又一个重载的startActivity(),继续跟进, 然后我又机智的找到关键一行代码:
mService.mWindowManager.deferSurfaceLayout();
            result = startActivityUnchecked(r, sourceRecord, voiceSession, voiceInteractor,
                    startFlags, doResume, options, inTask, outActivity);
  1. startActivityUncheckedLocked方法中只要执行了不同启动模式不同栈的处理,并最后调用了ActivityStack的startActivityLocked的重载方法:
ActivityStack.logStartActivity(
                EventLogTags.AM_CREATE_ACTIVITY, mStartActivity, mStartActivity.getTask());
        mTargetStack.mLastPausedActivity = null;

        sendPowerHintForLaunchStartIfNeeded(false /* forceSend */);

        mTargetStack.startActivityLocked(mStartActivity, topFocused, newTask, mKeepCurTransition,
                mOptions);

if (mDoResume) {
            final ActivityRecord topTaskActivity =
                    mStartActivity.getTask().topRunningActivityLocked();
            if (!mTargetStack.isFocusable()
                    || (topTaskActivity != null && topTaskActivity.mTaskOverlay
                    && mStartActivity != topTaskActivity)) {
               
                mTargetStack.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
                mWindowManager.executeAppTransition();
            } else {
                if (mTargetStack.isFocusable() && !mSupervisor.isFocusedStack(mTargetStack)) {
                    mTargetStack.moveToFront("startActivityUnchecked");
                }
                mSupervisor.resumeFocusedStackTopActivityLocked(mTargetStack, mStartActivity,
                        mOptions);
            }
        } else {
            mTargetStack.addRecentActivityLocked(mStartActivity);
        }
  1. 调用 ActivityStackSupervisor 的resumeFocusedStackTopActivityLocked方法
    boolean resumeFocusedStackTopActivityLocked(
            ActivityStack targetStack, ActivityRecord target, ActivityOptions targetOptions) {
        if (targetStack != null && isFocusedStack(targetStack)) {
            return targetStack.resumeTopActivityUncheckedLocked(target, targetOptions);
        }
        final ActivityRecord r = mFocusedStack.topRunningActivityLocked();
        if (r == null || r.state != RESUMED) {
            mFocusedStack.resumeTopActivityUncheckedLocked(null, null);
        } else if (r.state == RESUMED) {
            // Kick off any lingering app transitions form the MoveTaskToFront operation.
            mFocusedStack.executeAppTransition(targetOptions);
        }
        return false;
    }
  1. ActivityStack resumeTopActivityUncheckedLocked 方法
 boolean resumeTopActivityUncheckedLocked(ActivityRecord prev, ActivityOptions options) {
        if (mStackSupervisor.inResumeTopActivity) {
            // Don't even start recursing.
            return false;
        }

        boolean result = false;
        try {
            // Protect against recursion.
            mStackSupervisor.inResumeTopActivity = true;
            result = resumeTopActivityInnerLocked(prev, options);
        } finally {
            mStackSupervisor.inResumeTopActivity = false;
        }
        mStackSupervisor.checkReadyForSleepLocked();

        return result;
    }
  1. 调用ActivityStack resumeTopActivityInnerLocked方法
boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving, next, false);
        if (mResumedActivity != null) {
            if (DEBUG_STATES) Slog.d(TAG_STATES,
                    "resumeTopActivityLocked: Pausing " + mResumedActivity);
            pausing |= startPausingLocked(userLeaving, false, next, false);
        }
  1. startPausingLocked 方法作用就是让系统中栈中的Activity执行onPause方法
final boolean startPausingLocked(boolean userLeaving, boolean uiSleeping, boolean resuming,
            boolean dontWait) {
        ...
        if (prev.app != null && prev.app.thread != null) {
            if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "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);
            } catch (Exception e) {
                // Ignore exception, if process died other code will cleanup.
                Slog.w(TAG, "Exception thrown during pause", e);
                mPausingActivity = null;
                mLastPausedActivity = null;
                mLastNoHistoryActivity = null;
            }
        } else {
            mPausingActivity = null;
            mLastPausedActivity = null;
            mLastNoHistoryActivity = null;
        }
        ...
    }

prev.app.thread.schedulePauseActivity(), prev.app.thread 这个Thread 点进去其实是一个IApplicationThread接口对象,frameworks_base/core/java/android/app/IApplicationThread.aidl,这里又是一次进程间通信
在ActivityThread中也定义了一个ApplicationThread的类,其继承了IApplicationThread.Stub,所以这里相当于Binder通信的client端,而server端就是ActivityThread中的ApplicationThread

  1. ActivityThread中schedulePauseActivity的具体实现:
public final void schedulePauseActivity(IBinder token, boolean finished,
                boolean userLeaving, int configChanges, boolean dontReport) {
            int seq = getLifecycleSeq();
            if (DEBUG_ORDER) Slog.d(TAG, "pauseActivity " + ActivityThread.this
                    + " operation received seq: " + seq);
            sendMessage(
                    finished ? H.PAUSE_ACTIVITY_FINISHING : H.PAUSE_ACTIVITY,
                    token,
                    (userLeaving ? USER_LEAVING : 0) | (dontReport ? DONT_REPORT : 0),
                    configChanges,
                    seq);
        }
  1. 调用sendMessage(),调用一个重载的sendMessage,最后 mH.sendMessage(msg);mH就是一个handler
        private void sendMessage(int what, Object obj, int arg1, int arg2, int seq) {
            if (DEBUG_MESSAGES) Slog.v(
                    TAG, "SCHEDULE " + mH.codeToString(what) + " arg1=" + arg1 + " arg2=" + arg2 +
                            "seq= " + seq);
            Message msg = Message.obtain();
            msg.what = what;
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = obj;
            args.argi1 = arg1;
            args.argi2 = arg2;
            args.argi3 = seq;
            msg.obj = args;
            mH.sendMessage(msg);
        }
    
  2. 在Handler中处理消息:
     case PAUSE_ACTIVITY: {
                        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "activityPause");
                        SomeArgs args = (SomeArgs) msg.obj;
                        handlePauseActivity((IBinder) args.arg1, false,
                                (args.argi1 & USER_LEAVING) != 0, args.argi2,
                                (args.argi1 & DONT_REPORT) != 0, args.argi3);
                        maybeSnapshot();
                        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
                    } break;
    
  3. 调用 handlePauseActivity处理消息
private void handlePauseActivity(IBinder token, boolean finished,
            boolean userLeaving, int configChanges, boolean dontReport, int seq) {
        ActivityClientRecord r = mActivities.get(token);
       	    ......
            r.activity.mConfigChangeFlags |= configChanges;
            performPauseActivity(token, finished, r.isPreHoneycomb(), "handlePauseActivity");
            ......
            if (!dontReport) {
                try {
                // 调用完成后,通过IPC告知服务端activity的onPause方法调用完成
                    ActivityManager.getService().activityPaused(token);
                } catch (RemoteException ex) {
                    throw ex.rethrowFromSystemServer();
                }
            }
            mSomeActivitiesChanged = true;
        }
    }

  1. 继续调用 performPauseActivity----->重载 performPauseActivity
	    final Bundle performPauseActivity(ActivityClientRecord r, boolean finished,
	            boolean saveState, String reason) {
	      ... ...
	        if (finished) {
	            r.activity.mFinished = true;
	        }
	
	        // Next have the activity save its current state and managed dialogs...
	        if (!r.activity.mFinished && saveState) {
	            callCallActivityOnSaveInstanceState(r);
	        }
	
	        performPauseActivityIfNeeded(r, reason);
	
	       ... ...
	
	        return !r.activity.mFinished && saveState ? r.state : null;
	    }
  1. 然后调用 performPauseActivityIfNeeded
	    private void performPauseActivityIfNeeded(ActivityClientRecord r, String reason) {
	        if (r.paused) {
	            // You are already paused silly...
	            return;
	        }
	
	        try {
	           ...  ...
	            mInstrumentation.callActivityOnPause(r.activity);
	            
	            EventLog.writeEvent(LOG_AM_ON_PAUSE_CALLED, UserHandle.myUserId(),
	                    r.activity.getComponentName().getClassName(), reason);
	            
	        } catch (SuperNotCalledException e) {
	          ...  ...
	        r.paused = true;
	    }
  1. 调用了 mInstrumentation.callActivityOnPause (返回到Instrumentation类)
	public void callActivityOnPause(Activity activity) {
	        activity.performPause();
	    }
  1. 终于等到你!回到activity的方法了
	final void performPause() {
        mDoReportFullyDrawn = false;
        mFragments.dispatchPause();
        mCalled = false;
        onPause();
        mResumed = false;
        if (!mCalled && getApplicationInfo().targetSdkVersion
                >= android.os.Build.VERSION_CODES.GINGERBREAD) {
            throw new SuperNotCalledException(
                    "Activity " + mComponent.toShortString() +
                    " did not call through to super.onPause()");
        }
        mResumed = false;
    }

所以:我们在启动一个Activity的时候最先被执行的是栈顶的Activity的onPause方法
25. 最后,返回到 handlePauseActivity() 方法中
通过 ActivityManager.getService().activityPaused(token);告知服务端,客户端已完成activity方法的调用

 if (!dontReport) {
                try {
                    ActivityManager.getService().activityPaused(token);
                } catch (RemoteException ex) {
                    throw ex.rethrowFromSystemServer();
                }
            }

这个方法的最终调用时在ActivityManagerService的activityPaused方法执行,又是一次IPC通信

@Override
    public final void activityPaused(IBinder token) {
        final long origId = Binder.clearCallingIdentity();
        synchronized(this) {
            ActivityStack stack = ActivityRecord.getStackLocked(token);
            if (stack != null) {
                stack.activityPausedLocked(token, false);
            }
        }
        Binder.restoreCallingIdentity(origId);
    }
  1. 当栈顶activity的onPause()方法执行后,进入到ActivityStack 的activityPausedLocked方法中,其中有两个主要方法completePauseLocked(),和finishCurrentActivityLocke()。
    final void activityPausedLocked(IBinder token, boolean timeout) {
        ... ...

        final ActivityRecord r = isInStackLocked(token);
        if (r != null) {
            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
            if (mPausingActivity == r) {
              ... ...
                try {
                    completePauseLocked(true /* resumeNext */, null /* resumingActivity */);
                } finally {
                    mService.mWindowManager.continueSurfaceLayout();
                }
                return;
            } else {
                ... ...
               if (r.finishing) {
                        if (DEBUG_PAUSE) Slog.v(TAG,
                                "Executing finish of failed to pause activity: " + r);
                        finishCurrentActivityLocked(r, FINISH_AFTER_VISIBLE, false);
                    }
            }
        }
        mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
    }
  1. 继续跟进completePauseLocked(),和finishCurrentActivityLocke() ,发现在completePauseLocked中也调用了finishCurrentActivityLocke(),同时这两个方法都调用了addToStopping(),我就猜测重点应该是在这个方法
 void addToStopping(ActivityRecord r, boolean scheduleIdle, boolean idleDelayed) {
        if (!mStackSupervisor.mStoppingActivities.contains(r)) {
            mStackSupervisor.mStoppingActivities.add(r);
        }

        boolean forceIdle = mStackSupervisor.mStoppingActivities.size() > MAX_STOPPING_TO_FORCE
                || (r.frontOfTask && mTaskHistory.size() <= 1);
        if (scheduleIdle || forceIdle) {
            if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Scheduling idle now: forceIdle="
                    + forceIdle + "immediate=" + !idleDelayed);
            if (!idleDelayed) {
                mStackSupervisor.scheduleIdleLocked();
            } else {
                mStackSupervisor.scheduleIdleTimeoutLocked(r);
            }
        } else {
            mStackSupervisor.checkReadyForSleepLocked();
        }
    }

  1. scheduleIdleLocked 和 scheduleIdleTimeoutLocked 同时发送一个Handler消息

    void scheduleIdleTimeoutLocked(ActivityRecord next) {
    if (DEBUG_IDLE) Slog.d(TAG_IDLE,
            "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4));
    Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next);
    mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT);
    

    }

    final void scheduleIdleLocked() {
    mHandler.sendEmptyMessage(IDLE_NOW_MSG);
    }

  2. 然后根据消息类型,在handler中找到对应消息的处理

case IDLE_TIMEOUT_MSG: {
                    if (DEBUG_IDLE) Slog.d(TAG_IDLE,
                            "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj);
                    if (mService.mDidDexOpt) {
                        mService.mDidDexOpt = false;
                        Message nmsg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG);
                        nmsg.obj = msg.obj;
                        mHandler.sendMessageDelayed(nmsg, IDLE_TIMEOUT);
                        return;
                    }
                    //  同时调用了这个方法
                    activityIdleInternal((ActivityRecord) msg.obj,
                            true /* processPausingActivities */);
                } break;
                case IDLE_NOW_MSG: {
                    if (DEBUG_IDLE) Slog.d(TAG_IDLE, "handleMessage: IDLE_NOW_MSG: r=" + msg.obj);
                    activityIdleInternal((ActivityRecord) msg.obj,
                            false /* processPausingActivities */);
                } break;
  1. 跟进activityIdleInternal() 方法
void activityIdleInternal(ActivityRecord r, boolean processPausingActivities) {
            synchronized (mService) {
                activityIdleInternalLocked(r != null ? r.appToken : null, true /* fromTimeout */,
                        processPausingActivities, null);
            }
        }
  1. activityIdleInternalLocked 继续跟踪,看到两行重要代码
 for (int i = 0; i < NS; i++) {
            r = stops.get(i);
            final ActivityStack stack = r.getStack();
            if (stack != null) {
                if (r.finishing) {
                    stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false);
                } else {
                	// 1. stop
                    stack.stopActivityLocked(r);
                }
            }
        }

        // Finish any activities that are scheduled to do so but have been
        // waiting for the next one to start.
        for (int i = 0; i < NF; i++) {
            r = finishes.get(i);
            final ActivityStack stack = r.getStack();
            if (stack != null) {
            	// 2. destroy
                activityRemoved |= stack.destroyActivityLocked(r, true, "finish-idle");
            }
        }
  1. 目标stop 先跟踪第一个 ActivityStack中 stopActivityLocked(),发现了和pause调用时一个套路的,忘记的可以返回看看 step 16
final void stopActivityLocked(ActivityRecord r) {
       ... ...

        if (r.app != null && r.app.thread != null) {
         ... ...
         		// 和 pause一个套路的方法
                r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags);
                if (mService.isSleepingOrShuttingDownLocked()) {
                    r.setSleeping(true);
                }
                Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r);
                mHandler.sendMessageDelayed(msg, STOP_TIMEOUT);
            } catch (Exception e) {
             ... ...
            }
        }
    }

  1. 套路找到了,接下来就是回到ActivityThread 内部类 ApplicationThread中 找到scheduleStopActivity,嗯,验证一下,果然还是handler处理消息
  2. 根据STOP_ACTIVITY_SHOW消息类型 找到handleStopActivity()。
  private void handleStopActivity(IBinder token, boolean show, int configChanges, int seq) {
        ActivityClientRecord r = mActivities.get(token);
        if (!checkAndUpdateLifecycleSeq(seq, r, "stopActivity")) {
            return;
        }
        r.activity.mConfigChangeFlags |= configChanges;

        StopInfo info = new StopInfo();
        
        performStopActivityInner(r, info, show, true, "handleStopActivity");
		... ...
    }
  1. 很明显的只有一个performStopActivityInner()方法调用,跟进探探路
 private void performStopActivityInner(ActivityClientRecord r,
            StopInfo info, boolean keepShown, boolean saveState, String reason) {
        if (localLOGV) Slog.v(TAG, "Performing stop of " + r);
        if (r != null) {
           ... ... 
            // One must first be paused before stopped...
            // stop 之前 判断是否pause
            performPauseActivityIfNeeded(r, reason);

           ... ...

            // Next have the activity save its current state and managed dialogs...
            if (!r.activity.mFinished && saveState) {
                if (r.state == null) {
                    // 保存数据 OnSaveInstanceState
                    callCallActivityOnSaveInstanceState(r);
                }
            }

            if (!keepShown) {
                try {
                    // Now we are idle.
                    // 开始stop了
                    r.activity.performStop(false /*preserveWindow*/);
                } catch (Exception e) {
                  ... ...
                }
                r.stopped = true;
                EventLog.writeEvent(LOG_AM_ON_STOP_CALLED, UserHandle.myUserId(),
                        r.activity.getComponentName().getClassName(), reason);
            }
        }
    }
  1. 代码中注释,很明显就是Activity中的performStop(),里面有callActivityOnStop()方法,还是Instrumentation中的,还是原来的套路,还是原来的配方
    final void performStop(boolean preserveWindow) {
        mDoReportFullyDrawn = false;
        mFragments.doLoaderStop(mChangingConfigurations /*retain*/);
		... ...

            mFragments.dispatchStop();

            mCalled = false;
            mInstrumentation.callActivityOnStop(this);
            ... ....

            synchronized (mManagedCursors) {
                final int N = mManagedCursors.size();
                for (int i=0; i
  1. Duang Duang Duang!顺利调用了栈顶activity的onStop方法,而且OnSaveInstanceState方法目测是在onStop之前调用的。
    public void callActivityOnStop(Activity activity) {
        activity.onStop();
    }
  1. 这样下面就是onDestroy了,这个我们返回 第31 步,可以很明显的看到stack.destroyActivityLocked(),这个方法调用和onStop一模一样,我就不继续贴代码了,是时候让小伙伴们展现真正的技术了!后面会继续新activity的启动

你可能感兴趣的:(Android,原理探索)