Methods to introduce

  • Public void onConfigurationChanged(Configuration newConfig)

  • Scene:

    • The system calls this method when the configuration information of the system changes.
    • The premise is, in the manifest fileAndroidManifestConfiguration of theconfigChangesProperty corresponding to the device configuration, this method is called.
    • If the device configuration information changes withconfigChangesIf the property Settings are inconsistent, the Activity is destroyed and rebuilt with the new configuration.
    • To give you an example of the three sentences above, for example, switching between vertical and horizontal now,configChangesAttribute setandroid:configChanges="keyboard"The Activity will still destroy the rebuild because the properties it sets are inconsistent with the device information that occurred and should be set toandroid:configChanges="orientation|screenSize".
    • System configuration information: similar to the screen orientation, change the system font, display the hard keyboard…

Case study a vertical screen switch

1. No Settings in the Activity manifest fileconfigChangesProperties.

Conclusion: The activity is destroyed and rebuilt whenever the screen changes, not onConfigurationChanged.

2. Set in the Activity manifest fileandroid:configChanges="orientation|screenSize".

  • Conclusion: The activity will not be destroyed and rebuilt, and only the onConfigurationChanged method will be used for horizontal and vertical screen switches

  • Note:

    • If the value of targetSdkVersion is less than 13, you only need to configure orientation.

    • TargetSdkVersion value is greater than 13, must want to configure orientation | screenSize, otherwise only configuration orientation “, the activity will still be destroyed reconstruction.

Thank you

Blog.csdn.net/qq_27570955…