Android screen orientation change and onconfigurationchanged event

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.