Solution to not calling onConfigrationChange in andriod 4.0 or later versions
First, let's take a look at how the onConfigrationChange method was called in versions earlier than Android4.0:
1. First, add the permission in the manifest. xml file:
2. Configure the property: android: configChanges = "orientation | keyboardHidden" for the activity in the manifest. xml file"
3. Finally, inherit the method in the Activity class:
@ Override
Public void onConfigurationChanged (Configuration newConfig ){
Super. onConfigurationChanged (newConfig );
// You can switch the layout of the screen or any other operations you want.
If (newConfig. orientation = Configuration. ORIENTATION_LANDSCAPE) {textView. setText ("current screen is landscape");} else {textView. setText ("current screen is portrait ");}
}
Later, in version 4.2, various attempts did not call the onConfigurationChanged method, which was very strange. I understand that there is no doubt about calling this method when I was working on a project. What is the reason? This problem has been confusing for a long time. I will not talk about it anymore. Simply put, the solution is very simple. Modify the attributes of the manifest. xml file and add a screenSize to the end, as shown below:
Android: configChanges = "orientation | keyboardHidden | screenSize"
Then, it was really a problem with the Android version. Haha! This problem is finally solved.
Note the following:
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, you must note that ScreenSize must be added for Versions later than 4.0. Oh!