[Reprint] configchanges attribute usage in Activity

Source: Internet
Author: User
Tags spl
Pass Set This attribute allows activity to capture device status changes. The following content can be identified:
Config_font_scale
Config_mcc
Config_mnc
Config_locale
Config_touchscreen
Config_keyboard
Config_navigation
Config_orientation

Setting Method: Separate the following fields with the "|" symbol, for example, "locale | navigation | Orientation
"

Value Description
"MCC" The imsi mobile country code (MCC) has changed-that is, a sim hasbeen detected and updated the MCC. A mobile country number consists of three digits. Each country has its own independent MCC, which can be identified.Mobile phoneThe country to which the user belongs.
"MNC" The imsi mobile network code (MNC) has changed-that is, a sim hasbeen detected and updated the MNC. Mobile Network number, which is used to differentiate mobile phone users in a country or region.
"Locale" The locale has changed-for example, the user has selected a new language that text shoshould be diSPLAyed in. the user's region has changed.
"Touchscreen" The touchscreen has changed. (This shoshould never normally HAppEn .)
"Keyboard" The keyboard type has changed-for example, the user has plugged in an external keyboard.KeyboardModeChanged, for example, when a user accesses an external keyboardInput.
"Keyboardhidden" The keyboard accessibility has changed-for example, the user has slid the keyboard out to expose it. the user opens the hardware keyboard of the mobile phone.
"Navigation" The navigation type has changed. (This shoshould never normally happen .)
"Orientation" The screen orientation has changed-that is, the user has rotated the device. device rotation, horizontal display and vertical display mode switch.
"Fontscale" The font scaling factor has changed-that is, the user has selected a new global font size. The Global font size scaling changes

An example is provided to describe how to use this property: First, you need to modify the manifest of the project:
? View code XML

<Manifest Xmlns: Android = "http://schemas.android.com/ APK /RES/android"
Package = "com. androidres. configchangedtesting"
Android: versioncode = "1"
Android: versionname = "1.0.0" >
<Application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name" >
<Activity Android: Name = ". configchangedtesting"
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>

The Android: configchanges attribute is added to the activity to notify users when the specified attribute (configuration changes) changes.ProgramCall the onconfigurationchanged () function. Create a layout UI:
? View code XML

xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"


Android: id = "@ + ID/pick"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: TEXT = "pick"
/>

Android: id = "@ + ID/View"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: TEXT = "View"
/>

This simple UI contains two buttons, one of which is to select one through the contact listContactAnd view the details of the selected contact.

Project JavaSource code:
01. Import Android. App. activity;
02. Import Android. content. intent;
03. Import Android. content. res. configuration;
04. Import android.net. Uri;
05. Import Android. OS. Bundle;
06. Import Android. provider. Contacts. People;
07. Import Android. View. view;
08. Import Android. widget. Button;
09.

10. Public class configchangedtesting extends activity {
11./** called when the activity is first created .*/
12. Static final int pick_request = 1337;
13. Button viewbutton = NULL;
14. Uri contact = NULL;
15. @ override
16. Public void oncreate (bundle savedinstancestate ){
17. Super. oncreate (savedinstancestate );
18. // setcontentview (R. layout. Main );
19.

20. setupviews ();
21 .}
22.

23. Public void onconfigurationchanged (configuration newconfig ){
24. Super. onconfigurationchanged (newconfig );
25.

26. setupviews ();
27 .}
28.

29./* (non-javadoc)
30. * @ see Android. App. Activity # onactivityresult (INT, Int, Android. content. Intent)
31 .*/
32. @ override
33. Protected void onactivityresult (INT requestcode, int resultcode, intent data ){
34. // todo auto-generated method stub
35. // super. onactivityresult (requestcode, resultcode, data );
36.

37. If (requestcode = pick_request ){
38.

39. If (resultcode = result_ OK ){
40.

41. Contact = data. getdata ();
42. viewbutton. setenabled (true );
43 .}
44.

45 .}
46.

47 .}
48.

49. Private void setupviews (){
50.

51. setcontentview (R. layout. Main );
52.

53. Button pickbtn = (button) findviewbyid (R. Id. Pick );
54.

55. pickbtn. setonclicklistener (New View. onclicklistener (){
56.

57. Public void onclick (view v ){
58. // todo auto-generated method stub
59.

60. Intent I = new intent (intent. action_pick, people. content_uri );
61. startactivityforresult (I, pick_request );
62 .}
63 .});
64.

65. viewbutton = (button) findviewbyid (R. Id. View );
66.

67. viewbutton. setonclicklistener (New View. onclicklistener (){
68. Public void onclick (view ){
69. startactivity (new intent (intent. action_view, contact ));
70 .}
71 .});
72.

73. viewbutton. setenabled (contact! = NULL );
74 .}
75 .}

Article Source

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.