From: http://www.linuxidc.com/Linux/2011-06/36828.htm
Android screen orientation change and onconfigurationchanged event
Note: The onconfigurationchanged event can be triggered not only when the screen direction is changed, but also when other system settings are changed, such as opening or hiding the keyboard.
When the screen direction changes, the onconfigurationchanged event can be triggered. To capture this event for the current activity, we need to do the following.
1. Permission statement:
<Uses-Permission Android: Name = "android. Permission. change_configuration"> </uses-Permission>
The API says that this permission allows us to change the configuration information, but the permission is not used in the program that changes the screen direction. Does it conflict with each other? Here we can think that when we declare this permission, the system allows us to capture and modify some configuration information by rewriting the onconfigurationchanged method in activity.
Second, declare the event type to be captured by the activity,
For example
<Activity
Android: Name = ". ex05_23"
Android: Label = "@ string/app_name"
Android: configchanges = "orientation | keyboard">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>
The Android: configchanges attribute must be declared here, which specifies the event types that can be captured in the program. Multiple event types are separated by |.
If there is no orientation, the screen change events cannot be captured in the program.
Third:
Override the onconfigurationchanged method in the activity.
For example:
@ Override
Public void onconfigurationchanged (configuration newconfig ){
// When the screen Layout mode is horizontal in the new setting
If (newconfig. Orientation = activityinfo. screen_orientation_landscape)
{
// Some todo operations
}
Super. onconfigurationchanged (newconfig );
}
Bytes -------------------------------------------------------------------------------------
The following figure shows some parameters that newconfig can access:
Second, the value available in Android: configchanges = "": keyboard | MCC | MNC | locale | touchscreen | keyboardhidden | navigation | orientation ......
This article from the Linux community website (www.linuxidc.com) original link: http://www.linuxidc.com/Linux/2011-06/36828.htm