The basic concept of activity, and the life cycle of activity
First, the basic concept of activity
Activity is when you open an app and see an interactive interface that fills the window or hovers over other windows. For activity configuration in Androidmanifest.xml, an application can have multiple activity, and the main activity is configured in Androidmanifest.xml as follows:
<ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <ActivityAndroid:name= "Com.lisa.helloactivity.MainActivity"Android:label= "@string/app_name" > <Intent-filter> <action android:name= "Android.intent.action.MAIN" /> <category android:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> </Application>
The main activity needs to specify in the <intent-filter> node what the action and category child nodes are displayed on a yellow background, so that the first thing you see when the app starts is this page ... The main activity can jump to other pages by initiating other activity, which is done by using intent in the program to achieve the purpose, typically intent intent = new Intent (), Intent.setclass ( A.this, B.class) to accomplish the purpose of jumping from activity A to activity B.
The switch between the activity is done by pressing the stack (last in, first out), a new activtiy is switched to foreground, the new activity is pressed into the stack, at the top of the stack, the user focus is clicked, and after you click the back key, The activity at the top of the stack is stacked, the last activity reaches the top of the stack, and the user focus is retrieved again.
Ii. life cycle of activity
Let's start with a classic diagram of the life cycle:
Then there are 7 methods associated with Android's life cycle:
1. void OnCreate (Bundle savedinstancestate)
What is bundle savedinstancestate? A bundle is a key-value pair that stores the state of the current activity and is used to facilitate the recovery of state after Onresume or Onrestart.
2. void OnStart ()
3. void Onresume ()
4. void OnPause ()
5. void OnStop ()
6. void Onrestart ()
7. void Ondestory ()
Contains three key loops:
1. Complete life cycle: from onCreate () to ondestory () end
2.Visible life cycle: From OnStart () to onStop ()
3. The foreground life cycle (or the life cycle of the focus): from Onresume () to onPause ()
Android-activity life cycle