Activity模式之singleInstance的各种跳转

news/2024/11/23 13:43:59/

 

了解任务和返回堆栈  |  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


http://www.ppmy.cn/news/172396.html

相关文章

Linux 磁带机型号,请教一下,爱华的磁带机型号大全,里面的字母什么意思?

对爱华不太熟,以为每行开头就是一个型号,可是后面还是有型号,而且后面的字母和词组掺杂其中,那些字面和词组又是什么意思呢?看得我头疼!请教解答, 另外问一下,谁有比较详细的,按数字或字母顺序排列好的列表,谁有呢? 收集了HS所有的机器! HS-AFP10 HS-RDS70 YZ AI…

物联网开发与应用

小编分享 本书结合CC2530和ZigBee、CC1110和SimpliciTI、CC2540和低功耗蓝牙、CC3200和Wi-Fi,由浅入深地介绍物联网和云平台开发技术。全书采用任务式开发的学习方法,共积累了50多个趣味盎然、贴近社会和生活的案例,每个案例均有完整的开发过…

SQL刷题记录(一)

SQL刷题记录(一) 答主刚开始自学SQL,本专栏记录的是答主在牛客上刷题的过程。疑惑和部分思路都会写在习题下方。 题目来源:牛客网刷题网址 本文内容:T195-T225 T195. select * from employees order by hire_date …

DDD微服务架构设计第五课 设计支持快速交付的技术中台战略

12 如何设计支持快速交付的技术中台战略? 我们以往建设的系统都分为前台和后台,前台就是与用户交互的 UI 界面,后台就是服务端完成的业务逻辑操作。然而,在我们以往开发的很多业务系统中,有一些内容是共用的部分&…

Spring Boot 框架整体启动流程详解

基于Spring Boot 版本:3.1 Java: 17 Spring Boot 的入口即为xxApplication类的main方法: SpringBootApplication public class SpringBootDemoApplication {public static void main(String[] args) {SpringApplication.run(SpringBootDemoApplication.…

PCB工艺设计规范-01

定义: 导通孔(via):一种用于内层连接的金属化孔,但其中并不用于插入元件引线或其它增强材料。 盲孔(Blind via):从印制板内仅延展到一个表层的导通孔。 埋孔(Buried via):未延伸到印制板表面的一种导通孔。 过孔(Throu…

电感

电感作为三大基本元件之一,其重要性可想而知,作为硬件工程师,我们必须熟练掌握其特性。 笔者将结合自身经验,首先进行理论分析,尽可能用通俗易懂的描述,来阐述电感是什么,怎么产生的。理论的分析…

聊聊 Activity 栈的亲和关系

launchMode <activityandroid:name".ui.activity.TaskAffinityActivity"android:launchMode"singleTask" />standardsingleTopsingleTasksingleInstance 默认模式是 standard&#xff0c;这些模式分为两大类&#xff0c;standard 和 singleTop Act…