The life cycle of the activity during the Android switch _android

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 when

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

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

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, and then perform step 4, found that no longer print the same information, but print more than one line onconfigchanged

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

7, the Step 5 of the android:configchanges= "orientation" changed to
Android:configchanges= "Orientation|keyboardhidden", perform step 3 and print only
Onconfigchanged
Onconfigurationchanged-->

8, the implementation of step 4

Onconfigurationchanged-->
Onconfigurationchanged-->

Summary:

1. When the android:configchanges of the activity is not set, the screen will recall each lifecycle.
The horizontal screen is executed once, and the vertical screen is executed twice
2, set the activity of the android:configchanges= "orientation", the cut screen will be adjusted again
With each life cycle, the horizontal, vertical screen will only be executed once
3, set the activity of the android:configchanges= "Orientation|keyboardhidden",
The cut screen does not recall each lifecycle, only the Onconfigurationchanged method is executed

summarize the life cycle of the entire activity
Add that the current activity generates events that pop up toast and alertdialog when the life of the event
There's no change in the cycle
The activity runs by pressing the home key (same as being completely covered): Onsaveinstancestate-->
OnPause--> onStop onrestart-->onstart--->onresume
Activity not completely covered just lost focus: OnPause--->onresume
Related Article

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.