了解任务和返回堆栈 | Android 开发者 | Android Developers (google.cn)
例1:Activity跳转
画面跳转:MainActivity(standard)->FirstActivity(singleInstance)->SecondActivity(standard)
FirstActivity在其他栈中
Task id #211mFullscreen=truemBounds=nullmMinWidth=-1mMinHeight=-1mLastNonFullscreenBounds=nullTaskRecord{5a1ab5e #211 A=com.tech.activitymode U=0 StackId=1 sz=2}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tech.activitymode/.MainActivity }Hist #1: ActivityRecord{98acff6 u0 com.tech.activitymode/.SecondActivity t211}Intent { flg=0x10400000 cmp=com.tech.activitymode/.SecondActivity (has extras) }ProcessRecord{9db35d1 8978:com.tech.activitymode/u0a129}Hist #0: ActivityRecord{7168fae u0 com.tech.activitymode/.MainActivity t211}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tech.activitymode/.MainActivity }ProcessRecord{9db35d1 8978:com.tech.activitymode/u0a129}Task id #212mFullscreen=truemBounds=nullmMinWidth=-1mMinHeight=-1mLastNonFullscreenBounds=nullTaskRecord{d61c836 #212 A=com.tech.activitymode U=0 StackId=1 sz=1}Intent { flg=0x10000000 cmp=com.tech.activitymode/.FirstActivity (has extras) }Hist #0: ActivityRecord{5c059b1 u0 com.tech.activitymode/.FirstActivity t212}Intent { flg=0x10000000 cmp=com.tech.activitymode/.FirstActivity (has extras) }ProcessRecord{9db35d1 8978:com.tech.activitymode/u0a129}Running activities (most recent first):TaskRecord{5a1ab5e #211 A=com.tech.activitymode U=0 StackId=1 sz=2}Run #2: ActivityRecord{98acff6 u0 com.tech.activitymode/.SecondActivity t211}TaskRecord{d61c836 #212 A=com.tech.activitymode U=0 StackId=1 sz=1}Run #1: ActivityRecord{5c059b1 u0 com.tech.activitymode/.FirstActivity t212}TaskRecord{5a1ab5e #211 A=com.tech.activitymode U=0 StackId=1 sz=2}Run #0: ActivityRecord{7168fae u0 com.tech.activitymode/.MainActivity t211}mResumedActivity: ActivityRecord{98acff6 u0 com.tech.activitymode/.SecondActivity t211}
生命周期:
MainActivity onCreate
MainActivity onStart
MainActivity onResume
MainActivity onPause
FirstActivity onCreate
FirstActivity onStart
FirstActivity onResume
MainActivity onStop
FirstActivity onPause
SecondActivity onCreate
SecondActivity onStart
SecondActivity onResume
FirstActivity onStop
例2:Activity收到两次Intent
画面跳转:MainActivity(standard)->FirstActivity(singleInstance)->SecondActivity(standard)->FirstActivity(singleInstance)
FirstActivity未创建新的任务
Task id #212mFullscreen=truemBounds=nullmMinWidth=-1mMinHeight=-1mLastNonFullscreenBounds=nullTaskRecord{d61c836 #212 A=com.tech.activitymode U=0 StackId=1 sz=1}Intent { flg=0x10000000 cmp=com.tech.activitymode/.FirstActivity (has extras) }Hist #0: ActivityRecord{5c059b1 u0 com.tech.activitymode/.FirstActivity t212}Intent { flg=0x10000000 cmp=com.tech.activitymode/.FirstActivity (has extras) }ProcessRecord{9db35d1 8978:com.tech.activitymode/u0a129}Task id #211mFullscreen=truemBounds=nullmMinWidth=-1mMinHeight=-1mLastNonFullscreenBounds=nullTaskRecord{5a1ab5e #211 A=com.tech.activitymode U=0 StackId=1 sz=2}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tech.activitymode/.MainActivity }Hist #1: ActivityRecord{98acff6 u0 com.tech.activitymode/.SecondActivity t211}Intent { flg=0x10400000 cmp=com.tech.activitymode/.SecondActivity (has extras) }ProcessRecord{9db35d1 8978:com.tech.activitymode/u0a129}Hist #0: ActivityRecord{7168fae u0 com.tech.activitymode/.MainActivity t211}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tech.activitymode/.MainActivity }ProcessRecord{9db35d1 8978:com.tech.activitymode/u0a129}Running activities (most recent first):TaskRecord{d61c836 #212 A=com.tech.activitymode U=0 StackId=1 sz=1}Run #2: ActivityRecord{5c059b1 u0 com.tech.activitymode/.FirstActivity t212}TaskRecord{5a1ab5e #211 A=com.tech.activitymode U=0 StackId=1 sz=2}Run #1: ActivityRecord{98acff6 u0 com.tech.activitymode/.SecondActivity t211}Run #0: ActivityRecord{7168fae u0 com.tech.activitymode/.MainActivity t211}mResumedActivity: ActivityRecord{5c059b1 u0 com.tech.activitymode/.FirstActivity t212}
生命周期接例一
SecondActivity onPause
FirstActivity onNewIntent: data SecondActivity -> FirstActivity
FirstActivity onRestart
FirstActivity onStart
FirstActivity onResume
SecondActivity onStop
例三:back键下Activity的跳转
画面跳转:MainActivity(standard)->FirstActivity(singleInstance)->SecondActivity(standard)->点击back键,界面显示为MainActivity,
当SecondActivity为singleInstance时,点击back键返回FirstActivity,再次点击back键,返回MainActivity
Task id #219mFullscreen=truemBounds=nullmMinWidth=-1mMinHeight=-1mLastNonFullscreenBounds=nullTaskRecord{d9eaa22 #219 A=com.tech.activitymode U=0 StackId=1 sz=1}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tech.activitymode/.MainActivity }Hist #0: ActivityRecord{62241a1 u0 com.tech.activitymode/.MainActivity t219}Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tech.activitymode/.MainActivity }ProcessRecord{9cc5270 10163:com.tech.activitymode/u0a131}Task id #220mFullscreen=truemBounds=nullmMinWidth=-1mMinHeight=-1mLastNonFullscreenBounds=nullTaskRecord{fbd69e9 #220 A=com.tech.activitymode U=0 StackId=1 sz=1}Intent { flg=0x10000000 cmp=com.tech.activitymode/.FirstActivity (has extras) }Hist #0: ActivityRecord{8d72ff1 u0 com.tech.activitymode/.FirstActivity t220}Intent { flg=0x10000000 cmp=com.tech.activitymode/.FirstActivity (has extras) }ProcessRecord{9cc5270 10163:com.tech.activitymode/u0a131}Running activities (most recent first):TaskRecord{d9eaa22 #219 A=com.tech.activitymode U=0 StackId=1 sz=1}Run #1: ActivityRecord{62241a1 u0 com.tech.activitymode/.MainActivity t219}TaskRecord{fbd69e9 #220 A=com.tech.activitymode U=0 StackId=1 sz=1}Run #0: ActivityRecord{8d72ff1 u0 com.tech.activitymode/.FirstActivity t220}mResumedActivity: ActivityRecord{62241a1 u0 com.tech.activitymode/.MainActivity t219}
生命周期:
MainActivity onCreate
MainActivity onStart
MainActivity onResume
MainActivity onPause
FirstActivity onCreate
FirstActivity onStart
FirstActivity onResume
MainActivity onStop
FirstActivity onPause
SecondActivity onCreate
SecondActivity onStart
SecondActivity onResume
FirstActivity onStop
SecondActivity onPause
MainActivity onRestart
MainActivity onStart
MainActivity onResume
SecondActivity onStop
SecondActivity onDestroy