Two minutes to fully understand the detailed explanation of Android activity life cycle (graphic introduction)

BACK key: when we press the BACK key, our application will end. At this time, we will call onPause () ->onStop () ->onDestory () in three ways, as shown in the following figure:

Home key: when we open an application, such as a browser, I am browsing NBA news. When I see half of it, I suddenly want to listen to a song. At this time, we will choose to press the home key and then open the music application. When we press home, the activity successively executes onpause() - > onstop(). At this time, the application is not destroyed. As shown in the figure below:

Here we will lead to a problem. When we press the home key and then enter the activitydemo application, the state of our application should be the same as that before pressing the home key. Similarly, for convenience of understanding, I will modify the code of activitydemo by adding an EditText. Step 4: modify the main.xml layout file (add an EditText), and the code is as follows:

Obviously, this is not a qualified application, so we need to implement it in several methods of activity, as shown in step 6: modify the activitydemo.java code as follows:

OK, the great work has been basically completed. At this time, you can look back at the activity life cycle diagram. I think you should fully understand the activity life cycle. Do you understand it?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>