【Android源码 栏目提醒】:网学会员鉴于大家对Android源码 十分关注,论文会员在此为大家搜集整理了“Android应用程序启动过程源代码分析(2) - 技术总结”一文,供大家参考学习
Android应用程序启动过程源代码分析2Step8.ActivityStack.startActivityLocked这个函数定义在frameworks/base/services/java/com/
android/server/am/ActivityStack.java文件中publicclassActivityStack......finalintstartActivityLockedIApplicationThreadcallerIntentintentStringresolvedTypeUrigrantedUriPermissionsintgrantedModeActivityInfoaInfoIBinderresultToStringresultWhointrequestCodeintcallingPidintcallingUidbooleanonlyIfNeededbooleancomponentSpecifiedinterrSTART_SUCCESSProcessRecordcallerAppnullifcallernullcallerAppmService.getRecordForAppLockedcallerifcallerAppnullcallingPidcallerApp.pidcallingUidcallerApp.info.uidelse............ActivityRecordsourceRecordnullActivityRecordresultRecordnullifresultTonullintindexindexOfTokenLockedresultTo......ifindex0sourceRecordActivityRecordmHistory.getindexifrequestCode0sourceRecord.finishing......intlaunchFlagsintent.getFlagsiflaunchFlagsIntent.FLAG_ACTIVITY_FORWARD_RESULT0sourceRecordnull......iferrSTART_SUCCESSintent.getComponentnull......iferrSTART_SUCCESSaInfonull......iferrSTART_SUCCESS............ActivityRecordrnewActivityRecordmServicethiscallerAppcallingUidintentresolvedTypeaInfomService.mConfigurationresultRecordresultWhorequestCodecomponentSpecified......returnstartActivityUncheckedLockedrsourceRecordgrantedUriPermissionsgrantedModeonlyIfNeededtrue......从传进来的参数caller得到调用者的进程信息并保存在callerApp变量中这里就是Launcher应用程序的进程信息了。
前面说过参数resultTo是Launcher这个Activity里面的一个Binder对象通过它可以获得Launcher这个Activity的相关信息保存在sourceRecord变量中。
再接下来创建即将要启动的Activity的相关信息并保存在r变量中ActivityRecordrnewActivityRecordmServicethiscallerAppcallingUidintentresolvedTypeaInfomService.mConfigurationresultRecordresultWhorequestCodecomponentSpecified接着调用startActivityUncheckedLocked函数进行下一步操作。
Step9.ActivityStack.startActivityUncheckedLocked这个函数定义在frameworks/base/services/java/com/
android/server/am/ActivityStack.java文件中publicclassActivityStack......finalintstartActivityUncheckedLockedActivityRecordrActivityRecordsourceRecordUrigrantedUriPermissionsintgrantedModebooleanonlyIfNeededbooleandoResumefinalIntentintentr.intentfinalintcallingUidr.launchedFromUidintlaunchFlagsintent.getFlags//WellinvokeonUserLeavingbeforeonPauseonlyifthelaunching//activitydidnotexplicitlystatethatthisisanautomatedlaunch.mUserLeavinglaunchFlagsIntent.FLAG_ACTIVITY_NO_USER_ACTION0......ActivityRecordnotToplaunchFlagsIntent.FLAG_ACTIVITY_PREVIOUS_IS_TOP0r:null//IftheonlyIfNeededflagissetthenwecandothisiftheactivity//beinglaunchedisthesameastheonemakingthecall...oras//aspecialcaseifwedonotknowthecallerthenwecountthe//currenttopactivityasthecaller.ifonlyIfNeeded......ifsourceRecordnull......elseifsourceRecord.launchModeActivityInfo.LAUNCH_SINGLE_INSTANCE......elseifr.launchModeActivityInfo.LAUNCH_SINGLE_INSTANCEr.launchModeActivityInfo.LAUNCH_SINGLE_TASK......ifr.resultTonulllaunchFlagsIntent.FLAG_ACTIVITY_NEW_TASK0......booleanaddingToTaskfalseiflaunchFlagsIntent.FLAG_ACTIVITY_NEW_TASK0launchFlagsIntent.FLAG_ACTIVITY_MULTIPLE_TASK0r.launchModeActivityInfo.LAUNCH_SINGLE_TASKr.launchModeActivityInfo.LAUNCH_SINGLE_INSTANCE//Ifbringtofrontisrequestedandnoresultisrequestedand//wecanfindataskthatwasstartedwiththissame//componenttheninsteadoflaunchingbringthatonetothefront.ifr.resultTonull//Seeifthereisatasktobringtothefront.Ifthisis//aSINGLE_INSTANCEactivitytherecanbeoneandonlyone//instanceofitinthehistoryanditisalwaysinitsown//uniquetasksowedoaspecialsearch.ActivityRecordtaskTopr.launchModeActivityInfo.LAUNCH_SINGLE_INSTANCEfindTaskLockedintentr.info:findActivityLockedintentr.infoiftaskTopnull............ifr.packageNamenull//Iftheactivitybeinglaunchedisthesameastheonecurrently//atthetopthenweneedtocheckifitshouldonlybelaunched//once.ActivityRecordtoptopRunningNonDelayedActivityLockednotTopiftopnullr.resultTonulliftop.realActivity.equalsr.realActivity......else......booleannewTaskfalse//Shouldthisbeconsideredanewtaskifr.resultTonulladdingToTasklaunchFlagsIntent.FLAG_ACTIVITY_NEW_TASK0//todo:shoulddobettermanagementofintegers.mService.mCurTaskifmService.mCurTask
上一篇:
04
下一篇:
7*30m公路预应力混凝土连续梁桥上部结构设计