Call onConfigurationChanged when the Configuration Changes

The attribute android:configChanges="orientation|screenSize" of the activity element prevents the activity from being destroyed and recreated. Warning: this means that the res/values/strings.xml and res/values-land/strings.xml files, etc., will not be re-read. The background will not switch from the Mona Lisa to another painting. Instead, the onConfigurationChanged method of the activity is called and you’ll have to make all the adjustments yourself. See Handling the Configuration Change Yourself.

Source code in Etch.zip

  1. EtchActivity.java
  2. EtchView.java
  3. main.xml: unused.
  4. AndroidManifest.xml: added the attribute android:configChanges="orientation|screenSize" to the activity element.

Output

The output lists the fields of the Configuration object. The app was launched in portrait orientation. The first line of output was generated when we switched to landscape, the second line when we switched back to portrait.

adb logcat myTag:D '*:S'
D/myTag   ( 1287): {1.0 310mcc260mnc en_US layoutdir=0 sw320dp w533dp h320dp nrml long land finger qwerty/v/v tball/v s.27}
D/myTag   ( 1287): {1.0 310mcc260mnc en_US layoutdir=0 sw320dp w320dp h533dp nrml long port finger qwerty/v/v tball/v s.28}