Usage of configchanges attribute in activity

Source: Internet
Author: User

Usage of configchanges properties in activity-general discussion-Android Development Forum-Android Development Forum-Android Development-Android forum-Mobile Internet portal-Powered by discuz!

By setting this property, the activity captures the state of the device, and the following is what can be identified:??



Config_font_scale

Config_mcc

Config_mnc

Config_locale

Config_touchscreen

Config_keyboard

Config_navigation

Config_orientation



Set method: Use the following fields with the "|" Symbols separated, for example: "Locale|navigation|orientation"




Value : Description
Mcc : The IMSI Mobile Country Code (MCC) has Changed-that are, a SIM hasbeen detected and updated the MCC. Mobile country number, consisting of three digits, each country has Their own independent MCC, can identify the mobile phone users of the country.
on! : The IMSI Mobile Network Code (MNC) has Changed-that is, a SIM hasbeen detected and updated the MNC. Mobile network number, in a country or region, used for district breakup Service Provider for machine users
Locale : The locale has changed-for example, the user have selected a new language that text should is displayed in. The user's area is changed.
Touchscreen : The touchscreen has changed. (This should never normally happen.)
Keyboard : The keyboard type has changed-for example, the user have plugged in an external keyboard. The keyboard mode changes, for example: User access to external keyboard input.
Keyboardhidden : The keyboard accessibility has changed-for example, the user have slid the keyboard out to expose it. User opens the phone hardware keyboard
Navigation : The navigation type has changed. (This should never normally happen.)
Orientation : The screen orientation have changed-that is and the user has rotated the device. Equipment rotation, landscape display and vertical display mode switching.
Fontscale : The font scaling factor has changed-that are, the user has selected a new global font size. Global Font Size scaling changes





The use of this property is explained by an example: first you need to modify the manifest of the project:


    1. <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
    2. ? ?? ? package= "Com.androidres.ConfigChangedTesting"
    3. ? ?? ? android:versioncode= "1"
    4. ? ?? ? android:versionname= "1.0.0" >
    5. ? ? <application android:icon= "@drawable/icon" android:label= "@string/app_name" >
    6. ? ?? ??? <activity android:name= ". Configchangedtesting "
    7. ? ?? ?? ?? ?? ?? ? android:label= "@string/app_name"
    8. ? ?? ?? ?? ?? ?? ? android:configchanges= "Keyboardhidden|orientation" >
    9. ? ?? ?? ?? ?<intent-filter>
    10. ? ?? ?? ?? ?? ? <action android:name= "Android.intent.action.MAIN"/>
    11. ? ?? ?? ?? ?? ? <category android:name= "Android.intent.category.LAUNCHER"/>
    12. ? ?? ?? ?? ?</intent-filter>
    13. ? ?? ??? </activity>
    14. ? ? </application>
    15. </manifest>

Copy Code

    1. <manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
    2. ? ?? ? package= "Com.androidres.ConfigChangedTesting"
    3. ? ?? ? android:versioncode= "1"
    4. ? ?? ? android:versionname= "1.0.0" >
    5. ? ? <application android:icon= "@drawable/icon" android:label= "@string/app_name" >
    6. ? ?? ??? <activity android:name= ". Configchangedtesting "
    7. ? ?? ?? ?? ?? ?? ? android:label= "@string/app_name"
    8. ? ?? ?? ?? ?? ?? ? android:configchanges= "Keyboardhidden|orientation" >
    9. ? ?? ?? ?? ?<intent-filter>
    10. ? ?? ?? ?? ?? ? <action android:name= "Android.intent.action.MAIN"/>
    11. ? ?? ?? ?? ?? ? <category android:name= "Android.intent.category.LAUNCHER"/>
    12. ? ?? ?? ?? ?</intent-filter>
    13. ? ?? ??? </activity>
    14. ? ? </application>
    15. </manifest>

Copy Code

The Android:configchanges attribute is added to the activity to notify the program to call the Onconfigurationchanged () function when the specified attribute (Configuration changes) has changed. Create a layout UI:




    1. <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
    2. ? ? android:orientation= "Vertical"
    3. ? ? Android:layout_width= "Fill_parent"
    4. ? ? android:layout_height= "Fill_parent"
    5. ? ? >
    6. <button
    7. ? ?? ??? Android:id= "@+id/pick"
    8. ? ? Android:layout_width= "Fill_parent"
    9. ? ? android:layout_height= "Wrap_content"
    10. ? ? android:text= "Pick"
    11. ? ? />
    12. <button
    13. ? ?? ??? Android:id= "@+id/view"
    14. ? ? Android:layout_width= "Fill_parent"
    15. ? ? android:layout_height= "Wrap_content"
    16. ? ? android:text= "View"
    17. ? ? />
    18. </LinearLayout>

Copy Code

    1. <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
    2. ? ? android:orientation= "Vertical"
    3. ? ? Android:layout_width= "Fill_parent"
    4. ? ? android:layout_height= "Fill_parent"
    5. ? ? >
    6. <button
    7. ? ?? ??? Android:id= "@+id/pick"
    8. ? ? Android:layout_width= "Fill_parent"
    9. ? ? android:layout_height= "Wrap_content"
    10. ? ? android:text= "Pick"
    11. ? ? />
    12. <button
    13. ? ?? ??? Android:id= "@+id/view"
    14. ? ? Android:layout_width= "Fill_parent"
    15. ? ? android:layout_height= "Wrap_content"
    16. ? ? android:text= "View"
    17. ? ? />
    18. </LinearLayout>

Copy Code

This simple UI contains two buttons, one of which is to select a contact from the Contacts list, and the other is to view the details of the currently selected contact.



<ignore_js_op>

1.jpg (11.7 KB, download count:)

Download attachments

? Save to album

2011-10-25 00:03 Upload

?






Java source code for the project:




  1. Import android.app.Activity;??
  2. Import android.content.Intent;??
  3. Import android.content.res.Configuration;??
  4. Import Android.net.Uri;??
  5. Import Android.os.Bundle;??
  6. Import android.provider.Contacts.People;??
  7. Import Android.view.View;??
  8. Import Android.widget.Button;??
  9. public class Configchangedtesting extends Activity {??
  10. ? ? /** called when the activity is first created. */
  11. ? ? static final int pick_request = 1337;??
  12. ? ? Button viewbutton=null;??
  13. ? ? Uri contact = null;??
  14. ? ? @Override
  15. ? ? public void OnCreate (Bundle savedinstancestate) {??
  16. ? ?? ??? Super.oncreate (savedinstancestate);??
  17. ? ?? ??? Setcontentview (R.layout.main);??
  18. ? ?? ??? Setupviews ();??
  19. ? ? }??
  20. ? ? public void onconfigurationchanged (Configuration newconfig) {??
  21. ? ?? ?? ?? ?? ??? Super.onconfigurationchanged (newconfig);? ?
  22. ? ?? ?? ?? ?? ??? Setupviews ();??
  23. ? ? }? ?
  24. ? ? /* (Non-javadoc)
  25. ? ??? * @see android.app.activity#onactivityresult (int, int, android.content.Intent)
  26. ? ??? */
  27. ? ? @Override
  28. ? ? protected void Onactivityresult (int requestcode, int resultcode, Intent data) {??
  29. ? ?? ??? TODO auto-generated method stub??
  30. ? ?? ??? Super.onactivityresult (Requestcode, ResultCode, data);??
  31. ? ?? ??? if (Requestcode = = pick_request) {??
  32. ? ?? ?? ?? ? if (RESULTCODE==RESULT_OK) {??
  33. ? ?? ?? ?? ?? ? Contact = Data.getdata ();??
  34. ? ?? ?? ?? ?? ? Viewbutton.setenabled (true);??
  35. ? ?? ?? ?? ?}??
  36. ? ?? ???}??
  37. ? ? }??
  38. ? ? private void Setupviews () {??
  39. ? ?? ??? Setcontentview (R.layout.main);??
  40. ? ?? ??? Button pickbtn = (button) Findviewbyid (R.id.pick);??
  41. ? ?? ??? Pickbtn.setonclicklistener (New View.onclicklistener () {??
  42. ? ?? ?? ?? ? public void OnClick (View v) {??
  43. ? ?? ?? ?? ?? ? TODO auto-generated method stub??
  44. ? ?? ?? ?? ?? ? Intent i=new Intent (Intent.action_pick,people.content_uri);??
  45. ? ?? ?? ?? ?? ? Startactivityforresult (i,pick_request);??
  46. ? ?? ?? ?? ?}??
  47. ? ?? ???});??
  48. ? ?? ??? Viewbutton = (Button) Findviewbyid (R.id.view);? ?
  49. ? ?? ??? Viewbutton.setonclicklistener (New View.onclicklistener () {??
  50. ? ?? ?? ?? ?? ?? ??? public void OnClick (view view) {??
  51. ? ?? ?? ?? ?? ?? ?? ?? ? startactivity (New Intent (Intent.action_view, contact));??
  52. ? ?? ?? ?? ?? ?? ???}??
  53. ? ?? ???});? ?
  54. ? ?? ??? Viewbutton.setenabled (contact!=null);??
  55. ? ? }??
  56. }

Copy Code

Usage of configchanges attribute in activity

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.