Configeration知识android.docx_第1页
Configeration知识android.docx_第2页
Configeration知识android.docx_第3页
Configeration知识android.docx_第4页
Configeration知识android.docx_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【亲测】Activity中的 ConfigChanges 属性以及横竖屏切换时候 Activity 的生命周期 一、Activity 的 ConfigChanges 属性官方解释: 通过设置这个属性可以使Activity捕捉设备状态变化,以下是可以被识别的内容: CONFIG_FONT_SCALECONFIG_MCCCONFIG_MNCCONFIG_LOCALECONFIG_TOUCHSCREENCONFIG_KEYBOARDCONFIG_NAVIGATIONCONFIG_ORIENTATION设置方法:将下列字段用“|”符号分隔开,例如:“locale|navigation|orientation”ValueDescription “mcc“The IMSI mobile country code (MCC) has changed that is, a SIM hasbeen detected and updated the MCC.移动国家号码,由三位数字组成,每个国家都有自己独立的MCC,可以识别手机用户所属国家。 “mnc“The IMSI mobile network code (MNC) has changed that is, a SIM hasbeen detected and updated the MNC.移动网号,在一个国家或者地区中,用于区分手机用户的服务商。 “locale“The locale has changed for example, the user has selected a new language that text should be displayed in.用户所在地区发生变化。 “touchscreen“The touchscreen has changed. (This should never normally happen.) “keyboard“The keyboard type has changed for example, the user has plugged in an external keyboard.键盘模式发生变化,例如:用户接入外部键盘输入。 “keyboardHidden“The keyboard accessibility has changed for example, the user has slid the keyboard out to expose it.用户打开手机硬件键盘 “navigation“The navigation type has changed. (This should never normally happen.) “orientation“The screen orientation has changed that is, the user has rotated the device.设备旋转,横向显示和竖向显示模式切换。 “fontScale“The font scaling factor has changed that is, the user has selected a new global font size.全局字体大小缩放发生改变 项目的AndroidManifest.xml文件配置方法:view sourceprint?01 05 06 09 10 11 12 13 14 15 二、横竖屏切换时候 Activity 的生命周期 测试代码: view sourceprint?01public class AndroidLifecycle extends Activity 02private String TAG = AndroidLifecycle; 03public void onCreate(Bundle savedInstanceState) 04Log.i(TAG,AndroidLifecycle =onCreate()=); 05super.onCreate(savedInstanceState); 06setContentView(R.layout.main); 07 0809Override10protected void onSaveInstanceState(Bundle outState) 11Log.i(TAG,AndroidLifecycle =onSaveInstanceState()=); 12super.onSaveInstanceState(outState); 13 1415Override16protected void onRestoreInstanceState(Bundle outState) 17Log.i(TAG,AndroidLifecycle=onRestoreInstanceState()=); 18super.onRestoreInstanceState(outState); 19 2021Override22public void onConfigurationChanged(Configuration newConfig) 23Log.i(TAG,AndroidLifecycle =onConfigurationChanged()=); 24super.onConfigurationChanged(newConfig); 25 2627/ Called after onCreate or after onRestart when the activity had been 28/ stopped, but is now again being displayed to the user. It will be 29/ followed by onResume 30protected void onStart() 31Log.i(TAG,AndroidLifecycle =onStart()=); 32super.onStart(); 33 3435/ Called after onRestoreInstanceState, onRestart, or onPause, for your 36/ activity to start interacting with the user 37protected void onResume() 38Log.i(TAG,AndroidLifecycle =onResume()=); 39super.onResume(); 40 4142/ Called as part of the activity lifecycle when an activity is going into 43/ the background, but has not (yet) been killed 44protected void onPause() 45Log.i(TAG,AndroidLifecycle =onPause()=); 46super.onPause(); 47 4849/ Called when you are no longer visible to the user. You will next receive 50/ either onRestart, onDestroy, or nothing, depending on later user 51/ activity. 52protected void onStop() 53Log.i(TAG,AndroidLifecycle =onStop()=); 54super.onStop(); 55 5657/ Perform any final cleanup before an activity is destroyed 58protected void onDestroy() 59Log.i(TAG,AndroidLifecycle =onDestroy()=); 60super.onDestroy(); 61 6263/ Called after onStop when the current activity is being re-displayed to 64/ the user (the user has navigated back to it). It will be followed by 65/ onStart and then onResume 66protected void onRestart() 67Log.i(TAG,AndroidLifecycle =onRestart()=); 68super.onRestart(); 69 70 Activity属性配置: view sourceprint?01 02 05 06 07 08 09 1011 在 Android 2.2 模拟器上测试结果为: 1、不设置Activity的android:configChanges时: Simulator_切换到横屏 Simulator_切换到竖屏 模拟器这种情况切屏会重新调用各个生命周期,切横屏时会生命周期执行一次,切竖屏时生命周期会执行两次,且横竖屏onConfigurationChanged未被调用。但是在HTC DESIRE HD(G10) 这款手机上测试结果为:生命周期都只执行一次,且横竖屏onConfigurationChanged未被调用。 2、设置Activity的android:configChanges=orientation时: Simulator_orientation_切换到横屏 Simulator_orientation_切换到竖屏 模拟器这种情况切屏还是会重新调用各个生命周期,切横屏onConfigurationChanged未执行、竖屏时onConfigurationChanged执行1次。但是在HTC DESIRE HD(G10) 这款手机上测试结果为:生命周期未发生变化,且横竖屏onConfigurationChanged都只执行一次。 3、设置Activity的android:configChanges=orientation|keyboardHidden时: Simulator_orientation_keyboardHidden_切换到横屏 Simulator_orientation_keyboardH

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论