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 -->