Activity is one of the most basic and most common components of Android components (Activity,service services, content provider, Broadcastreceiver broadcast receivers).
The concept of activity:
Activity it is essentially a form, such as when we open the software it is just a form to present in front of you. It can interact with the user in the basic graphical rendering unit.
The difference is that activity is not minimized by this concept. On the Windows platform there is a concept of maximization, and the form on the Apple platform is also not maximized, only the concept of sizing the form
Three states of activity:
We open an app casually
This time we're looking at this activity of dialing, right? (running state) We click the Home button.
When we click Back to the desktop, the activity of the dial is not visible, this time belongs to (stop state)
And then we press and hold the home button
Then the activity behind us is (paused)
Activity life cycle:
So the life cycle, we have to open a site activity life cycle diagram, then, we get this picture, I will explain to you the operation process.
1. What's the first step? The activitylaunched is started, and after it is started, a OnCreate () method is executed first, then a OnStart () method is executed. And then we'll do a Onresume () method,
2. The activity will be in operation only after the Onresume is executed. And then we can see that activityrunning is the other activity that's going to be in front of us,
3. Our current activity executes a onpause () callback method. Go down again. If our activity is in an invisible state, that is, a stop state, a callback method such as OnStop () is executed.
4. If an activity is paused and stopped, let's look at the process on the left. If there are other applications with higher priority, it needs memory. Our operating system will kill our activity. At this point our application is completely stopped and the memory is freed. Then let's use some of our higher-memory priority applications. If the user is going to navigate to our wall again, then it will re-execute our OnCreate () method. is a process like this.
5. Then, if an application is in a paused state. Like the call procedure above us. We press the home button long and then we come back and the user comes back to our dialing page. It will re-execute our Method Onresume () method.
6 Then if an application is in a stop state. The user then navigates back to our program, which executes a onstop () method. Here's one thing to note: If the application where our activity resides is not destroyed. The Onrestart () method is re-executed from the paused state to the running state. Then execute OnStart () and then perform a process such as onresume ().
7. So when does the OnDestroy () method be executed? OnDestroy () This method means that the OnDestroy () method is executed when the activity is destroyed by the system, and after the Ondestroty () method is executed, our application is completely shut down.
This is the life cycle of the activity.
Activity detail life cycle (Android)