Activity in Android is used to display the user interface, which is the interface that the user sees and acts on.
The activity component in the Androidmanifest file that contains the filter below is the default startup class for the program, which is automatically called by the system when the program starts.
< Intent-filter > < android:name= "Android.intent.action.MAIN"/> < android:name= "Android.intent.category.LAUNCHER"/></ Intent-filter >
Activity Life Cycle Chart ↓
Here OnCreate () (Create), OnStart () (start), Onresume () (recovery) is not to say, all for run to prepare.
OnPause () state and OnPause ()->onresume () status
When activity is obscured (there is another transparent activity or toast, alertdialog, etc.), such as jumping from mainactivity to secondactivity (transparent), Then the mainactivity is in the OnPause () state, and when the return key is returned from Secondactivity to Mainactivity, the mainactivity State is OnPause ()->onresume ().
OnStop () state and OnStop ()->onrestart->onstart () status
When actvity is completely invisible, for example, when mainactivity presses the home key back to the desktop or jumps to an opaque activity, the mainactivity is in the OnStop () state. Return to Mainactivity again by OnStop ()->onrestart ()->onstart ().
OnDestroy () status
Die
State on the left
When other applications need to use memory and the program is killed when there is not enough memory, it needs to be recreated
The following example helps to understand: (view its cycle from the Logcat log)
Note: There are three interfaces in the instance, where secondactivity is transparent and mainactivity is the main interface
1. Open the application to enter mainactivity
2, jump from mainactivity to secondactivity
3, jump from secondactivity to thirdactivity
4. Press the back button from Thirdactivity back to Secondactivity
5. Press the back button from Secondactivity back to Mainactivity
6. Press the home button from mainactivity to return to the desktop
7. Back to Mainactivity from the desktop
8. Press the Back button from Mainactivity to exit the application
The activity life cycle of Android four components