当前位置:网站首页>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 :

边栏推荐
- 普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
- 互联网协议
- "Dream Cup" 2017 Jiangsu information and future primary school summer camp it expert PK program design questions
- A simple example of delegate usage
- Realize ray detection, drag the mouse to move the object and use the pulley to scale the object
- Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
- How to play video on unityui
- 关于在云服务器上(这里用腾讯云)安装mysql8.0并使本地可以远程连接的方法
- 创意信息获2家机构调研:GreatDB 数据库已在9地部署
- [untitled]
猜你喜欢

Deeply understand the characteristics of database transaction isolation

通过 Play Integrity API 的 nonce 字段提高应用安全性

Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)

2021 summary and 2022 outlook
![[pyqt] the cellwidget in tablewidget uses signal and slot mechanism](/img/0e/02265f7195ca0add4155694530822a.png)
[pyqt] the cellwidget in tablewidget uses signal and slot mechanism

seata 1.3.0 四種模式解决分布式事務(AT、TCC、SAGA、XA)

Using ENSP to do MPLS pseudo wire test

Online hard core tools
![[STM32] actual combat 3.1 - drive 42 stepper motors with STM32 and tb6600 drivers (I)](/img/cd/7cd8e2e77419c65d633a2a235b2362.png)
[STM32] actual combat 3.1 - drive 42 stepper motors with STM32 and tb6600 drivers (I)

解决VSCode只能开两个标签页的问题
随机推荐
After the uniapp jumps to the page in onlaunch, click the event failure solution
verilog设计抢答器【附源码】
V-for img SRC rendering fails
seata 1.3.0 四种模式解决分布式事务(AT、TCC、SAGA、XA)
Bookmarking - common website navigation for programmers
从色情直播到直播电商
[untitled]
JS array delete the specified element
IDEA快捷键大全
How to use cherry pick?
Eth trunk link switching delay is too high
Long list performance optimization scheme memo
Verilog 实现数码管显视驱动【附源码】
JS add spaces to the string
[untitled]
uniCloud
A case of compiling QT file qmake compiling script
Deeply understand the characteristics of database transaction isolation
[OneNote] can't connect to the network and can't sync the problem
[untitled]