& Lt; Android & gt; android: configChanges attribute from form leakage,

Source: Internet
Author: User

<Android> android: configChanges attributes,

Today, I had the honor to go to my buddy's big company to work as a temporary worker for half a day. A occasional Bug has been tossing him for a long time. I finally caught the exception Log today, which roughly means android. view. windowleaked -- form leakage. I checked the information online:

Every Activity in Android has a WindowManager form Manager. The dialog box built on an Activity and the PopupWindow also have the corresponding WindowManager form manager. Because Dialog and popup1_wn cannot exist independently from the Activity, when the Activity carrying a Dialog or displaying a PopupWindow is completed (), and the Dialog (or PopupWindow) if you do not exit normally, the Window Leaked error will be thrown. Because no one in the WindowManager of this Dialog (or PopupWindow) can be attached, its form manager will be Leaked.

According to this information, it is found that the screen is suddenly displayed when the new Activity is started (the sdk developed by the buddy supports horizontal and vertical screen switching), because in AndroidManifest. the android: configChanges attribute is not configured in xml. In this case, the Activity re-calls the onCreate method, that is, the entire lifecycle is re-called. At this time, the Dialog has no dismiss, this results in form leakage. The solution becomes so simple, in AndroidManifest. configure the android: configChanges attribute in xml, so that the onConfigurationChanged method of the Activity will be called when the screen is switched horizontally and vertically, and the entire lifecycle will not be called again. We finally configured android: configChanges = "screenSize | orientation | keyboardHidden | navigation ".


Now that we have talked about the android: configChanges attribute, I have made further research. Based on the online information, I have summarized the following:

1. If the android: configChanges of the Activity is not set, the entire life cycle is called again when the screen is switched, the whole screen is switched once, And the portrait screen is switched twice.

2. When setting the Activity's android: configChanges = "orientation", the entire lifecycle will be re-called when the screen is switched, and only one time is executed when the screen is switched horizontally or vertically.

3. When the android: configChanges = "orientation | keyboardHidden" of the Activity is set, the entire life 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. So 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 ".

-- The above information is found on the Internet and is very useful, but it has not been verified by myself. However, I believe it is also issued by LZ and should be very useful.

Attached android: configChanges attribute explanation:

VALUE DESCRIPTION
"Mcc" The Country Code of the International Mobile User identification code is changed ----- the sim is detected, and the mcc to be updated is the country code of the mobile user
"Mnc" The mobile network number of the International Mobile User identification code is changed ------ the sim is detected. The mnc to update is a mobile network number, which consists of up to two digits to identify the mobile communication network to which the mobile user belongs
"Locale" Address Changed ----- a new language is displayed
"Touchscreen" The touch screen is changed ------ it usually does not happen
"Keyboard" The keyboard has changed-for example, the user uses an external keyboard.
"KeyboardHidden" The keyboard availability has changed.
"Navigation" Navigation has changed-usually not
"ScreenLayout" Screen Display changed ------ different displays are activated
"FontScale" The font ratio has changed-different global fonts are selected.
"UiMode" The user mode has changed.
"Orientation" Screen direction changed
"ScreenSize" Screen size changed
"SmallestScreenSize" The physical size of the screen has changed, for example, connecting to an external screen.














Today, we have gained a lot of insights into the domineering nature of big companies, and have also deepened our understanding of android: configChanges attributes.


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.