具体案例
- 利用栈后进先出的特点,可以解决一些特定的算法问题
有效括号问题(LeetCode第20题)
问题描述
给定一个只包括 ‘(‘,’)’,’{‘,’}’,’[‘,’]’ 的字符串,判断字符串是否有效。
realStartActivityLocked方法中有一段非常重要的代码1
2
3
4
5
6
7
8
9
10
11
12final boolean realStartActivityLocked(ActivityRecord r, ProcessRecord app,
        boolean andResume, boolean checkConfig) throws RemoteException {
    //...
    
    app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken,
            System.identityHashCode(r), r.info, new Configuration(mService.mConfiguration),
            new Configuration(task.mOverrideConfig), r.compat, r.launchedFromPackage,
            task.voiceInteractor, app.repProcState, r.icicle, r.persistentState, results,
            newIntents, !andResume, mService.isNextTransitionForward(), profilerInfo);
    
    //...                
}
| 1 | /* | 
我们从Activity的startActivity方法开始分析,该方法有几种重载方式,但最终都会调用startActivityForResult方法,该方法实现如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15public void startActivityForResult(@RequiresPermission Intent intent, int requestCode,
        @Nullable Bundle options) {
    if (mParent == null) {	//只需关注这部分代码
        //...
			
        Instrumentation.ActivityResult ar =
            mInstrumentation.execStartActivity(
                this, mMainThread.getApplicationThread(), mToken, this,
                intent, requestCode, options);     //先看Instrumentation的execStartActivity方法(exec是execute的缩写,意为执行)
			
	//...
    } else {
        //...
    }
}
我们看下Instrumentation的execStartActivity方法