The life cycle of Android activity

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.