惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
T
Tenable Blog
博客园_首页
S
Securelist
Spread Privacy
Spread Privacy
Google Online Security Blog
Google Online Security Blog
Forbes - Security
Forbes - Security
Engineering at Meta
Engineering at Meta
U
Unit 42
L
LINUX DO - 热门话题
量子位
T
Threat Research - Cisco Blogs
博客园 - 【当耐特】
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
Martin Fowler
Martin Fowler
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Security Latest
Security Latest
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
Know Your Adversary
Know Your Adversary
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
V2EX - 技术
V2EX - 技术
T
Tailwind CSS Blog
月光博客
月光博客
Recent Announcements
Recent Announcements
G
Google Developers Blog
F
Full Disclosure
W
WeLiveSecurity
宝玉的分享
宝玉的分享
腾讯CDC
G
GRAHAM CLULEY
Vercel News
Vercel News
Simon Willison's Weblog
Simon Willison's Weblog
美团技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security

博客园 - 好好学习,天天进步

Java调用ocx控件以及dll pongo英雄会-修路题解(z) 那些VisualStudio隐藏的调试功能(转) 那些有争议的编程观点 经过完整测试的农历-公历相互转换 windows phone SDK 8.0 模拟器异常 0x89721800解决办法 JavaScript 解析器相关资料 AST Parser。。。 (转)浏览器的工作原理:新式网络浏览器幕后揭秘 中缀表达式转后缀表达式(逆波兰表达式) Windows 8 无法安装 Algorithm Gossip: 中序式轉後序式(前序式) tesseract-ocr训练方法 透明窗口与不规则窗口制作方法总结 检测文件存在的四种方法 C/C++多种方法获取文件大小 从浏览器启动客户端程序 Struts 2命令执行漏洞 win7 x64怎么枚举所有快捷键呢 在windbg中测试shadow ssdt , win32k!NtUserGetForegroundWindow , hook shadow ssdt
Android 横屏切换竖屏Activity的生命周期(转)
好好学习,天天进步 · 2013-04-12 · via 博客园 - 好好学习,天天进步

曾经遇到过一个面试题,让你写出横屏切换竖屏Activity的生命周期。现在给大家分析一下他切换时具体的生命周期是怎么样的: 
1、新建一个Activity,并把各个生命周期打印出来 
2、运行Activity,得到如下信息 
onCreate--> 
onStart--> 
onResume--> 
3、按crtl+f12切换成横屏时 
onSaveInstanceState--> 
onPause--> 
onStop--> 
onDestroy--> 
onCreate--> 
onStart--> 
onRestoreInstanceState--> 
onResume--> 
4、再按crtl+f12切换成竖屏时,发现打印了两次相同的log 
onSaveInstanceState--> 
onPause--> 
onStop--> 
onDestroy--> 
onCreate--> 
onStart--> 
onRestoreInstanceState--> 
onResume--> 
onSaveInstanceState--> 
onPause--> 
onStop--> 
onDestroy--> 
onCreate--> 
onStart--> 
onRestoreInstanceState--> 
onResume--> 
5、修改AndroidManifest.xml,把该Activity添加 android:configChanges="orientation",执行步骤3 
onSaveInstanceState--> 
onPause--> 
onStop--> 
onDestroy--> 
onCreate--> 
onStart--> 
onRestoreInstanceState--> 
onResume--> 
6、再执行步骤4,发现不会再打印相同信息,但多打印了一行onConfigChanged 
onSaveInstanceState--> 
onPause--> 
onStop--> 
onDestroy--> 
onCreate--> 
onStart--> 
onRestoreInstanceState--> 
onResume--> 
onConfigurationChanged--> 
7、把步骤5的android:configChanges="orientation" 改成 android:configChanges="orientation|keyboardHidden",执行步骤3,就只打印onConfigChanged 
onConfigurationChanged--> 
8、执行步骤4 
onConfigurationChanged--> 
onConfigurationChanged--> 
总结: 
1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次 
2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次 
3、设置Activity的android:configChanges="orientation|keyboardHidden"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法 
总结一下整个Activity的生命周期 
补充一点,当前Activity产生事件弹出Toast和AlertDialog的时候Activity的生命周期不会有改变 
Activity运行时按下HOME键(跟被完全覆盖是一样的):onSaveInstanceState --> onPause --> onStop       onRestart -->onStart--->onResume 
Activity未被完全覆盖只是失去焦点:onPause--->onResume