Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Activity Lifecycle in Android

Shulou Source: shulou.com Published: 2022-06-01 02:40:36 11月06日 Update

This article mainly introduces the example analysis of Activity life cycle in Android, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.

Life cycle of Activity

Life cycle: when the object is born, when it dies, how to write the code, where the code is written.

Note:

When a new Activity is opened and the transparent theme is adopted, the current Activity will not call back the onStop

OnCreate and onDestroy pairing, onStart and onStop pairing (visible), onResume and onPause pairing (whether it is in the foreground, can interact with the user)

When you open a new Activity, the relevant Log is:

Main1Activity: onPause Main2Activity: onCreate Main2Activity: onStart Main2Activity: onResume MainA1ctivity: onStop

Life cycle in an abnormal state:

Resource-related system configuration changes or insufficient resources: for example, if the screen is rotated, the current Activity will be destroyed, and the onSaveInstanceState will be called back before onStop to save the data, and the onRestoreInstanceState will be called back after onStart when the Activity is recreated. Where Bundle data is passed to onCreate (not necessarily data) and onRestoreInstanceState (there must be data).

To prevent rebuilding when the screen is rotated, add the configuration to the manifest file:

Android:configChanges= "orientation" Thank you for reading this article carefully. I hope the article "sample Analysis of the Life cycle of Activity in Android" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Time cycle life data articles examples analysis code screen resources configuration topics values interests foreground at the same time objects files more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia Xiaomi Shulou Technology vpn