Android: configChanges property Summary,

Source: Internet
Author: User

Android: configChanges property Summary,

1. for android: configChanges attributes, it is generally considered as follows:
1. When the android: configChanges of the Activity is not set, the life cycle of the screen is re-called, the screen is executed once, and the screen is split twice.
2. When setting the Activity's android: configChanges = "orientation", the screen will be switched to call each lifecycle, and the screen will be executed only once
3. When the android: configChanges = "orientation | keyboardHidden" of the Activity is set, the live cycle is not re-called and only the onConfigurationChanged method is executed.

However, since Android 3.2 (API 13), after setting the android: configChanges = "orientation | keyboardHidden" of the Activity, it will call the lifecycle again. Because the screensize also changes with the switch between devices. Therefore, in AndroidManifest. when the MiniSdkVersion and TargetSdkVersion attributes set in xml are greater than or equal to 13, if you want to prevent the program from re-loading the Activity during runtime, in addition to setting "orientation ", you must also set "ScreenSize ".
Solution:
Set android: configChanges = "orientation | keyboardHidden | screenSize" in AndroidManifest. xml

 

Ii. Example:

1. Create an Activity and print the lifecycle of the Activity.

2. Run the Activity and obtain the following information:

OnCreate -->

OnStart -->

OnResume -->

3. When switching to landscape screen by pressing crtl + f12

OnSaveInstanceState -->

OnPause -->

OnStop -->

OnDestroy -->

OnCreate -->

OnStart -->

OnRestoreInstanceState -->

OnResume -->

4. When you press crtl + f12 to switch to the portrait screen, the same log is printed twice.

OnSaveInstanceState -->

OnPause -->

OnStop -->

OnDestroy -->

OnCreate -->

OnStart -->

OnRestoreInstanceState -->

OnResume -->

OnSaveInstanceState -->

OnPause -->

OnStop -->

OnDestroy -->

OnCreate -->

OnStart -->

OnRestoreInstanceState -->

OnResume -->

5. Modify AndroidManifest. xml, add android: configChanges = "orientation" to the Activity, and perform step 3.

OnSaveInstanceState -->

OnPause -->

OnStop -->

OnDestroy -->

OnCreate -->

OnStart -->

OnRestoreInstanceState -->

OnResume -->

6. Execute Step 4 again and find that the same information will not be printed, but an onConfigChanged line will be printed.

OnSaveInstanceState -->

OnPause -->

OnStop -->

OnDestroy -->

OnCreate -->

OnStart -->

OnRestoreInstanceState -->

OnResume -->

OnConfigurationChanged -->

7. Change android: configChanges = "orientation" in step 3 to android: configChanges = "orientation | keyboardHidden". After step 3 is executed, only onConfigChanged is printed.

OnConfigurationChanged -->

8. Step 4

OnConfigurationChanged -->

OnConfigurationChanged -->

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.