The life cycle of the activity when switching between the screen and the

Source: Internet
Author: User

1. Create a new activity and print out each life cycle

2, run the activity, get the following information

Oncreate-->
Onstart-->
Onresume-->

3, press CRTL+F12 switch Cheng

Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->

4, and then press CRTL+F12 to switch to vertical screen, found that two times the same log was printed

Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->

5, modify the Androidmanifest.xml, add the activity android:configchanges= "orientation", perform step 3

Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->

6, then perform step 4, found that the same information will not be printed, but more than print a line onconfigchanged

Onsaveinstancestate-->
Onpause-->
Onstop-->
Ondestroy-->
Oncreate-->
Onstart-->
Onrestoreinstancestate-->
Onresume-->
Onconfigurationchanged-->

7, change step 5 android:configchanges= "orientation" to android:configchanges= "Orientation|keyboardhidden", perform step 3, Just print onconfigchanged

Onconfigurationchanged-->

8. Perform step 4

Onconfigurationchanged-->onconfigurationchanged-->

Summarize:

1, do not set the activity of the android:configchanges, the screen will recall the various life cycle, cut across the screen will be executed once, cut the vertical screen will be executed twice

2, set the activity android:configchanges= "orientation", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once

3, set the activity android:configchanges= "Orientation|keyboardhidden", the screen will not recall the various life cycle, will only execute onconfigurationchanged method

Summarize the life cycle of the activity

To add, the activity's life cycle will not change when the current activity generates an event that pops up toast and alertdialog

When the activity is running, press the home key (the same as when it is fully overwritten): Onsaveinstancestate---OnPause-onStop onrestart-->onstart--->onresu Me

Activity not being completely overwritten just loses focus: onPause--->onresume

Transferred from: http://www.360doc.com/content/11/0526/18/3700464_119590329.shtml#

The life cycle of the activity when switching between the screen and the

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.