Activity life cycle

Source: Internet
Author: User

Open directly

OnCreate the method to invoke when the activity is to open (starting)

OnStart the method that is called when the UI of the current activity is visible to the user

Onresume Current activity starts responding to user interaction (the activity gets to the focus call method)


Press the back key

OnPause the current activity loses focus call method (becomes background)

OnStop The current Activity interface The user cannot see the calling method

OnDestroy perform some cleanup operations when the activity is being destroyed


minimizing applications

OnPause

OnStop




Activity life cycle can be divided into 3 types according to the range


1. Full life cycle oncreate create OnStart user visible Onresume Get focus onpasue lose focus OnStop user is not visible ondestory destroyed.


2. Visual life cycle interface always visible to users

OnStart () Visible onresume get focus onpasue lose focus OnStop () User not visible

Onrestart ()

3. Foreground life cycle Onresume-onpause




Screen switching is actually the process of activity destruction and reconstruction.


Workaround

1. Fixed screen orientation

<activity

android:screenorientation= "Portrait"//Vertical screen

android:screenorientation= "Landscape"//Horizontal screen

/>


2. Ignore changes in the screen

<activity

Android:configchange= "Orientation|keyboardhidden|screensize"

/>


Activity life cycle

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.