The life cycle of Android activity has 7 methods, namely OnCreate (), OnStart (), Onrestart (), Onresume (), OnPause (), OnStop (), Ondestory ().
There are three loops: 1. The complete loop: from OnCreate () to the end of Ondestory (). OnCreate ()->onstart ()->onresume ()->onpause ()->onstop ()->ondestory (). Run all the way to the head
2. Visible loop: Runs from OnStart () to OnStop () end. OnStart ()->onresume ()->onpause ()->onstop ()->onrestart ()->onstart (). After you open a new activity and completely overwrite the old activity, use the Back button to re-display the old activity
3. Interactive loop: Runs from Onresume () to OnPause () end. Onresume ()->onpause ()->onresume (). New activity is not fully covered by the old activity, and the old activity is re-displayed by the back key
OnCreate (): The initialization of data in general.
OnStart (): When this method is called, the activity is already visible to the user, but not necessarily at the foreground.
Onresume (): When this method is called, activity is in the foreground and can interact with the user.
OnPause (): When this method is called, activity is paused, which is partially visible. Whenever a new activity is created, you must call the OnPause () method. Data that requires persistent retention is stored in the OnPause () method
OnStop (): When this method is called, activity is in a stopped state, which is completely invisible. The OnStop () method must be called as long as the current activity is completely invisible.
Ondestory (): When called to this method, the entire program is closed.
Onrestart (): This method is called when the old activity is completely invisible and is displayed by the back key.
These are called when the system is fully memory
Toggle: Perform OnPause (), OnStop (), Ondestory (), then execute OnCreate (), OnStart (), Onrestart (), Onresume (). Destroy the current activity, re-create a new activity, the switch between the screen is this process.
Switching order between activity: aactivity switches to bactivity, executes aactivity onpause (), then executes Bactivity oncreate (), OnStart (), Onresume (), Finally execute the aactivity onstop (). Aactivity the portion of the consumption resource is closed, then switch to Bactivity to execute the OnCreate () method, initialize the data, and display the interface in the bactivity. When Bactivity has implemented the Onresume () method, the user can interact and then execute the OnStop () method in Aactivity, which is time-consuming but runs in the background and has no effect on the user's use.
The life cycle of Android activity