Android: configchanges = "keyboardhidden | orientation" is not used in androidmanifest. xml files. Of course, it is useful.
If this attribute is configuredThis function is called directly during screen switching.The onconfigurationchanged method in the oncreate method does not re-execute the oncreate method.If this attribute is not configured, The oncreate method will be re-called. The following is a test
Androidmanifest. xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TestActivity"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Main. xml file
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Textview
Android: Id = "@ + ID/TV"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "horizontal and vertical screen switching test"
/>
<Edittext
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Id = "@ + ID/ET"
/>
</Linearlayout>
Testactivity. Java File
Package com. test;
Import Android. App. activity;
Import Android. content. res. configuration;
Import Android. OS. Bundle;
Import Android. widget. edittext;
Import Android. widget. textview;
Public class testactivity extends activity {
Edittext et;
Textview TV;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
ET = (edittext) findviewbyid (R. Id. Et );
TV = (textview) findviewbyid (R. Id. TV );
System. Out. println ("I am the oncreate method ");
}
@ Override
Public void onconfigurationchanged (configuration newconfig ){
Super. onconfigurationchanged (newconfig );
If (newconfig. Orientation = configuration. orientation_landscape ){
TV. settext ("Landscape ");
} Else {
TV. settext ("portrait ");
}
}
}
You can test it to verify the conclusion I just mentioned:"When the Android: configchanges = "keyboardhidden | orientation" attribute is configured in the XML file, the oncreate method of the activity will not be re-executed when the screen is switched over, but the onconfigurationchanged method will be executed, otherwise, the oncreate method will be re-executed during the switchover."