当前位置:网站首页>Activity lifecycle
Activity lifecycle
2022-07-07 11:14:00 【Brick factory worker】
Activity Life cycle
One 、 Life cycle diagram

Two 、 The callback method
- onCteate(): When Activity When it was first created , Will execute this method . Generally, some initialization will be done , Input the binding of events .
- onStart(): When Activity When displayed to the user , Will execute this method . At this point, the user can see this Activity, But no interaction , It can be simply understood as seeing , Unable to touch .
- onResume(): When Activity At the front desk , Will execute this method . At this point, the user can contact the Activity Interact , And at this time Activity Stack top . That is, you can see and touch it .
- onPause(): When there is another Activity Overwrite current Activity when , Will execute this method . Previous Activity Will lose focus and save data , And it's visible , Just can't interact with users .
- onStop(): When Activity It's not visible , Will execute onStop(), At this moment Activity Will run in the background , It's not going to be destroyed .
- onDestroy(): When you click the return key on the system interface , Will execute Activity Of finish() Method , At this time Activity Will be destroyed .
- onRestart(): When the second Activity After being destroyed , first Activity Will return to the front desk , This method will be executed . But Scene 2 corresponds to FirstActivity This method will not be executed , Because it is displayed in the form of pop-up SecondActivity, Not completely covered FirstActivity, therefore FirstActivity No implementation onStop(), It won't execute onRestart() The method , The principle can refer to the above life cycle diagram .
3、 ... and 、 Examples demonstrate
Two are used here Activity give an example :FirstActivity、SecondActivity. Rewrite all life cycle methods , Print log .
Scene one :SecondActivity Adopted and FirstActivity The same default full screen display .
- When to start FirstActivity when , Will execute FirstActivity Of onCteate()、onStart()、onResume() Method . as follows :

- Click on FirstActivity The first button in , Jump to SecondActivity, here FirstActivity Will execute onPause()、onStop() Method , Thus invisible . and SecondActivity Will be created , perform onCteate()、onStart()、onResume() Method . as follows :

- Click the phone return button , Equivalent to execution Activity Of finish() Method . here SecondActivity Will be destroyed , Will execute onPause()、onStop()、onDestroy() Method . and FirstActivity Will return to the front desk , Will execute onRestart()、onStart()、onResume() Method . as follows :

- Click back again ,FirstActivity It's going to be destroyed , One after another onPause()、onStop()、onDestroy() Method .

Scene two :SecondActivity Display in the form of pop-up window .
- When to start FirstActivity when , Will execute FirstActivity Of onCteate()、onStart()、onResume() Method . as follows :

- Click on FirstActivity The first button in , Jump to SecondActivity, here FirstActivity Only execute onPause() Method , It's partially visible . and SecondActivity Will be created , perform onCteate()、onStart()、onResume() Method . as follows :

- Click the phone return button , Equivalent to execution Activity Of finish() Method . here SecondActivity Will be destroyed , Will execute onPause()、onStop()、onDestroy() Method . and FirstActivity Will be Partially visible To All visible , Only execute onResume() Method . as follows :

- Click back again ,FirstActivity It's going to be destroyed , One after another onPause()、onStop()、onDestroy() Method . as follows :

边栏推荐
- Unity websocket server
- seata 1.3.0 四种模式解决分布式事务(AT、TCC、SAGA、XA)
- uniapp 在onLaunch中跳转页面后,点击事件失效解决方法
- What if copying is prohibited?
- Qtcreator sets multiple qmake
- CentOS系统下Redis安装和自启动配置的步骤
- Project ERROR: Unknown module(s) in QT: core gui
- Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)
- [C #] the solution of WinForm operation zoom (blur)
- Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
猜你喜欢

Web端自动化测试失败的原因

2021 summary and 2022 outlook

July 10, 2022 "five heart public welfare" activity notice + registration entry (two-dimensional code)

shardingsphere分库分表示例(逻辑表,真实表,绑定表,广播表,单表)

SQL Server knowledge gathering 9: modifying data

"Dream Cup" 2017 Jiangsu information and future primary school summer camp it expert PK program design questions

技术分享 | 抓包分析 TCP 协议

Transaction rolled back because it has been marked as rollback-only解决

uniCloud

Static semantic check of clang tidy in cicd
随机推荐
2021-04-08
Array object sorting
Idea shortcut keys
Go Slice 比较
高考作文,高频提及科技那些事儿……
Online hard core tools
关于SIoU《SIoU Loss: More Powerful Learning for Bounding Box Regression Zhora Gevorgyan 》的一些看法及代码实现
From pornographic live broadcast to live broadcast E-commerce
RationalDMIS2022 高级编程宏程序
Arduino receives and sends strings
Kitex 重试机制
VR development optimization
Mysql的json格式查询
uniapp 在onLaunch中跳转页面后,点击事件失效解决方法
Still cannot find RPC dispatcher table failed to connect in virtual KD
Eth trunk link switching delay is too high
2021 summary and 2022 outlook
Introduction to shell programming
verilog设计抢答器【附源码】
VIM命令模式与输入模式切换