Question: What is the life cycle of the activity when switching between screens?
Answer:
1, do not set the activity of the android:configchanges, the screen will recall the various life cycle, cut across the screen will be executed once, cut the vertical screen will be executed twice
2, set the activity android:configchanges= "orientation", the screen will recall the various life cycle, cut horizontal, vertical screen will only be executed once
3, set the activity android:configchanges= "Orientation|keyboardhidden", the screen will not recall the various life cycle, will only execute onconfigurationchanged method
But after testing, the results show that not all are consistent with the ' answer ':
Test environment: Test results on HTC t329d 4.1 and simulator 2.2.3:
1, and the 1th inconsistency in the answer. When you do not set the activity's android:configchanges, you will only recall the life cycle once, regardless of whether you cut the horizontal screen or the vertical screen.
2.2nd consistent with ' answer '
3, and the 3rd inconsistency in the answer. When setting the activity's android:configchanges= "Orientation|keyboardhidden", before Android 3.2 (API level 13), the screen will recall the various lifecycles, The Onconfigurationchanged () method is not executed. You must add screensize to Configchanges after Android 3.2 to not recall the individual lifecycles when you cut the screen. and execute the onconfigurationchanged () method.
The inconsistency between the test results and the ' answer ' tells me that it is better to have a good pro-test for the so-called ' answer ', and that it is better to point out the test environment to the person who gave the answer, otherwise there is no comparison between the test results. Thoroughly and thoroughly cover as many of the knowledge about configuration change as possible. In fact, for the 1th, cutting horizontal screen or vertical screen results in the number of activity reconstruction is not important, it is important that it is rebuilt and the reconstruction will cause problems.
The configuration class describes all the configuration information for a device that affects the resources retrieved by the application. Includes user-specified options (locale and scaling), as well as the device itself configuration (for example, input modes,screen size and screen orientation). You can see all the effects of the configuration in this class The property of the change.
Screen switching is the most common factor that affects configuration changes, and there are many other factors that affect the configuration (such as switching between English and Chinese), the usability of the keyboard (this is not understood), etc.
Common properties that cause configuration change:
Toggle Screen: android:configchanges= "Orientation"
Keyboard availability: android:configchanges= "Keyboardhidden"
Screen size change: android:configchanges= "ScreenSize"
Language changes: android:configchanges= "Locale"
When the program runs, if a configuration change occurs that causes the current activity to be destroyed and recreated, the call to OnDestroy is followed by the call to the OnCreate () method. The purpose of rebuilding is to allow applications to adapt to new configurations by automatically loading alternative resources.