Detailed introduction to the life cycle of Android activity

Detailed introduction to the life cycle of Android activity

Life cycle describes the methods that a class will execute from creation (New) to death (garbage collection). In this process, different methods will be called for different life stages.

Activity is one of the four components in Android. It is the most common application component and the most used component. It can provide an interface to interact with users. There are many states of an activity from creation to destruction. From one state to another, the corresponding callback methods will be triggered. These callback methods include oncreate ondestory OnStart onstop onresume onpause. These methods correspond to each other, oncreate -- > create and ondestory -- > destroy; OnStart -- > visible and onstop -- > invisible; Onresume -- > editable (focus) and onpause -- > do not get focus. The last method is onrestart. When will this method be called? When the activity is onstop but there is no ondestory, that is, it is not destroyed, the user will call onrestart method when returning to the current activity. Here, the oncreate method is no longer called.

The complete life cycle of an activity: oncreate -- > OnStart -- > onresume -- > onpause -- > onstop -- > ondestory. When the user clicks the return key, the activity will be destroyed. At this time, the activity is first uneditable, then invisible, and finally destroyed. When the user clicks the home key, it means that he will return to the desktop. At this time, the activity will not be destroyed. Therefore, the reality here cannot be edited and will no longer be visible. At this time, the ondestrory method will not be called to be destroyed. At this time, clicking to enter the application will call the onrestart method, no longer the activity, and then OnStart and onresume.

The following is the life cycle diagram of activity:

Thank you for reading, hope to help you, thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>