The activity life cycle of Android four components

Source: Internet
Author: User

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

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.