--by Cy[[email protected]]
1. protected void OnCreate (Bundle savedinstancestate) {throw new RuntimeException ("stub!"); }
When an activity is created, the system automatically calls the OnCreate method to complete the creation work. This creation includes layouts, bindings for listeners, and so on.
First of all, the bundle is a key-value pair, similar to map, the communication between two activity can be implemented by bundle class.
The Bundle Savedinstancestate object is the state of the Save program when it was last closed (frozen), or the state before the freeze can be saved by overriding the Onfreeze method. When the program starts (when the Activity is reinitialized), the OnCreate method is called again, and the previous freeze state is obtained from the savedinstancestate, and the contents of this activity can be passed to the next activity through bundles.
When an activity is completed, it needs to be saved in savedinstancestate, and when other activity is created, the data can be obtained from it.
2.protected void Onsaveinstancestate (Bundle outstate) {throw new RuntimeException ("stub!"); }
Activity in Android is saved by the Onsaveinstancestate () method, and in the OnCreate or Onrestoreinstancestate method, the function is restored, If run through the Onrestart method, only the Onsaveinstancestate method is executed.
Figure 1-1 is the life cycle of Android activity.
Figure 1-1
3. protected void Onrestoreinstancestate (Bundle savedinstancestate) {throw new RuntimeException ("stub!");}
Explanation See 2nd article
4. protected void Onrestart () {throw new RuntimeException ("stub!"); }
Explanation See 2nd article
5. protected void OnStart () {throw new RuntimeException ("stub!"); }
Here's a combination of OnCreate, OnStart, Onresume, OnPause, Onrestart, OnStop, OnDestroy method. When an activity is started, the system calls OnCreate, OnStart, Onresume methods in turn.
When starting Activity2 from Activity1, the OnPause method of Activity1 is called first, then Activity2 OnCreate, OnStart, Onresume method are called, to completely overwrite activity1, Then the OnStop method of Activity1 is called last.
OnCreate method:
- The first time the activity is created, it is called by the system
- The role is to set the layout file, bind the Listener
OnStart Method:
- When activity is visible, the method is called
Onresume Method:
- The method is called when the user can get the current focus
OnPause Method:
- When a new activity obscures the current activity, the method saves the data in the current activity
Onrestart Method:
- When an activity is not destroyed (called the OnDestroy method), the Onrestart method is called when the activity is used again
OnStop Method:
- The system calls this method when the current activity is completely invisible
OnDestroy Method: