Activity is the most frequent and basic module for Android Developers. In Android programs, activity generally represents a screen on the mobile phone screen. If you compare a mobile phone to a browser, activity is equivalent to a webpage. In the activity, we can add some button elements or check
Box. You can see that the activities can jump to each other. For example, after you press a button, the activity may jump to another activity. A little different from a webpage jump is that the jump between activities may return values, for example, from activity
When a jumps to Activity B
When B finishes running, it may return a value to activity. In many cases, this is quite convenient.
When a new screen is opened, the previous screen is paused and pushed into the history stack. You can return to a previously opened screen through the rollback operation. We can choose a screen that does not need to be retained. Therefore, Android will save the start of each application to the current screen in the stack.
An activity is maintained by the Android system and has its own lifecycle, that is, a cycle of its generation, operation, and destruction ...... Understanding the lifecycle of an activity is very helpful for programming.
--- Android
Development and Practice
1. oncreate ()
Called when an activity is created.
This function is called only once in the acitvity life cycle.
Has a parameter, or is null, or is saved in advance through the onsaveinstancestate () function.
2. onstart ()
Called when the activity is to be displayed to the user.
3. onresume ()
Called when the activity can interact with the user.
This function is optimal if you want to play music or animations.
4. onpause ()
Called when the activity is about to enter the background.
Usually when a new activity is started and displayed, you need to save the program persistent data, such as the data record being edited.
5. onstop ()
This API is called when the activity is invisible and is not required for a period of time.
If the memory is insufficient, the function may never be called and the system will directly stop the process.
6. onrestart ()
Called when the activity is changed from stop to visible again.
7. ondestroy ()
Called before the activity is destroyed.
When the memory is insufficient, the function may never be called and the system will directly stop the process.