Android:configchanges Attribute Considerations

Source: Internet
Author: User

Android:configchanges= "Keyboardhidden|orientation" is configured when you turn the screen

The oncreate will still be called because the screensize property is not configured to cause it.

Reference: http://blog.csdn.net/huiguixian/article/details/8071821

In previous versions, as long as the activity was specified android:configchanges= "keyboardhidden|orientation" property in the Androidmanifest.xml file, The OnCreate () function is not called again when the screen is turned, but instead calls Onconfigurationchanged ().

However, since android3.2, if you set this up again, you will notice that OnCreate () is still called after the screen is turned, not onconfigurationchanged (); Trace the framework layer code, you will find the problem, is because Google in android3.2 added screensize change Notice, in the Turn screen, not only orientation changed, screensize also changed, but in the judgment is to call onconfigurationchanged or ONCR When Eate, the following judgment is used:

int diff = activity.mCurrentConfig.diff (config);

if (diff! = 0) {

If This activity doesn ' t handle any of the config changes and then don ' t bother calling onconfigurationchanged as we ' regoin G to destroy it.

if ((~activity.mactivityinfo.getrealconfigchanged () & diff) = = 0) {

Shouldchangeconfig = true;

}

}

public int getrealconfigchanged () {

Return Applicationinfo.targetsdkversion < Android.os.Build.VERSION_CODES. HONEYCOMB_MR2? (Configchanges | Activityinfo.config_screen_size

| activityinfo.config_smallest_screen_size): configchanges;

}

With the above analysis, there are two ways to solve the problem: (only modify Androidmanifest.xml)

1. Specify android:configchanges= "Keyboardhidden|orientation|screensize", and the other code is treated like the previous code;

2. In Androidmanifest.xml, specifying Targetsdkversion as the previous version of 3.2 (version number 13 for 3.2), the system automatically adds ScreenSize property values.

For example: <uses-sdk android:minsdkversion= "3" android:targetsdkversion= "/>"

The first method is recommended.

Android:configchanges Attribute Considerations

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.