Preface: because bloggers I was cooking chicken chicken, but also want to have their own learning record, so I did not write a blog, although the Internet has a lot of predecessors summary of oliver, I as compared to the elder people is like a spark compared to the sun, but always have a record the process of slowly, I also believe that slowly will be improved. Although I’m not sure I will be one of the best written, spoken also seems too crazy hh, but I promise I don’t copy, reference will indicate the source, ensure that the content of their written entirely correct within a certain amount of time as far as possible, after all, technology changes with each passing day, I want to ensure that always right nor too reality (this blog reference “exploration of Android development art creation).

Summary of the Activity

Activity is one of the four most basic and commonly used Android components. An Activity is an application component that provides a screen that users can interact with in order to complete a task. All actions in an Activity are closely related to the user. It is a component responsible for interacting with the user. You can use setContentView(View) to display specific controls. In an Android application, an Activity is usually a single screen that displays controls and listens to and responds to user events. Activities communicate with each other through intEnts.

According to the understanding of a blogger, an Activity is a page that can interact with users, but sometimes this page can also be Fragment(this will be mentioned later). As for why I need to learn its life cycle, to be honest, I did not pay attention to it at the beginning of learning Android. Everything is done in Oncreate(). This is not a problem in the beginning, but the more you learn, the more important the lifecycle is. Some operations must be done in the proper method.

Activity Lifecycle

1.onCreate

This is the first method performed when the Activity is loaded, while the Activity is not yet visible. In this method, we perform lightweight operations such as data initialization, loading layout, etc. After all, we want the user to see our Activity as quickly as possible.

2.onStart

When executing this method, it means that the Activity is being started, but it is still not visible to the user. To be honest, I am not sure what the meaning of this method is. After reading some information, I feel that it is not clear.

3.onResume

When it comes to this method, the Activity is officially in the foreground, at the top of the task stack, and is ready to start receiving and interacting with the user.

4.onPause

If we start an ActivityA and then start an ActivityB within ActivityA, the ActivityA lifecycle state will move from onResume to onPause before executing ActivityB’s OnCreate method. This method, as the name suggests, is paused, but it is important to note that popping a user-level Dialog over a running Activity does not trigger this method, only a system-level dialog.

5.onStop

Indicates that the Activity is about to stop. You can use this method to perform some heavyweight tasks, such as reclaiming resources and saving data, as mentioned in the Google training document.

6.onRestart

If you have not called the onDestroy method mentioned below but have left the Activity (for example, by pressing the Home button to return to the desktop), this method is called when you restart an Activity, as the name suggests.

7.onDestroy

If the Back key is pressed, the Activity dies, calling the onDestroy method, which does some recycling and the final release of the resource.

Conclusion:

So far several life cycle said, but just dug a pit called task stack, this feeling and start mode combined said better, the next post, and several operations lead to life cycle changes are often asked in the interview, if also put in this feeling a little long, also put together in the next good. Tomorrow is the birthday of the motherland hemp, happy National Day!