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

边栏推荐
猜你喜欢

【C#】WinForm运行缩放(变糊)的解决方法

Deep understanding of Apache Hudi asynchronous indexing mechanism

Transaction rolled back because it has been marked as rollback only
![[machine learning 03] Lagrange multiplier method](/img/14/7d4eb5679606e272f137ddbda4938c.png)
[machine learning 03] Lagrange multiplier method
![[untitled]](/img/8e/e968d4629004bb0c3ee70328b6777b.jpg)
[untitled]

oracle常见锁表处理方式

90后,辞职创业,说要卷死云数据库
![[OneNote] can't connect to the network and can't sync the problem](/img/28/9a02b1da0f43889989a9539c9fb6b6.png)
[OneNote] can't connect to the network and can't sync the problem
![[untitled]](/img/f0/a34c116a793e844da46c7cd407224b.jpg)
[untitled]

Interprocess communication (IPC)
随机推荐
Vscode 尝试在目标目录创建文件时发生一个错误:拒绝访问【已解决】
Unity downloads files through the server address
vim 的各种用法,很实用哦,都是本人是在工作中学习和总结的
uniCloud
【C#】WinForm运行缩放(变糊)的解决方法
毕业季|与青春作伴,一起向未来!
V-for img SRC rendering fails
Bookmarking - common website navigation for programmers
The opacity value becomes 1%
Unity script visualization about layout code
Avoid mutating a prop directly since the value will be overwritten whenever the parent component
滚动踩坑--UNI_APP(八)
Simple and easy to modify spring frame components
Online hard core tools
基于Retrofit框架的金山API翻译功能案例
oracle常见锁表处理方式
Verilog 实现数码管显视驱动【附源码】
The concept, implementation and analysis of binary search tree (BST)
[pyqt] the cellwidget in tablewidget uses signal and slot mechanism
互联网协议