b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

android 横竖屏切换生命周期调用

电脑杂谈  发布时间:2019-08-21 05:03:26  来源:网络整理

同时调用2次vb程序_onresume 调用2次_jsp调用js方法调用

先来看看android:configChanges属性

android:configChanges=["mcc", "mnc", "locale","touchscreen", "keyboard", "keyboardHidden","navigation", "screenLayout", "fontScale", "uiMode","orientation", "screenSize", "smallestScreenSize"]mcc:The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC.IMSI(国际移动客户识别码)发生改变,检测到SIM卡,或者升级MCCmnc:The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC.IMSI网络出现改变,检测到SIM卡,或者升级MCC其中mcc和mnc理论上不可能出现变化locale:The locale has changed — 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 revealed the hardware keyboard.键盘发生改变,例如,用户使用了软件鼠标navigation:The navigation type (trackball/dpad) has changed. (This should never normally happen.)导航发生改变,(这一般不需要出现) 举例:连接蓝牙按键,连接后确实造成了navigation的类型出现差异。

因为连接蓝牙鼠标后,我可以使用方向键来navigate了screenLayout:The screen layout has changed — this might be caused by a different display being activated.屏幕的布局出现改变,这可能引起激活不同的显示fontScale:The font scaling factor has changed — the user has selected a new global font size.全局字体大小缩放发生改变orientation:The screen orientation has changed — that is, the user has rotated the device.设备翻转,横向显示和纵向显示机制切换。screenSize: 屏幕大小改变了smallestScreenSize: 屏幕的物理大小改变了,如:连接到一个外部的屏幕上4.2提高了一个layoutDirection属性,当改变语言设定后,该属性也会成newConfig中的一个mask位。所以ActivityManagerService(实际在ActivityStack)在决定能否重启Activity的之后总是判断为重启。需要在android:configChanges 中同时添加locale和layoutDirection。在不退出应用的状况下切换到Settings里切换语言,发现该Activity还是重启了。

同时调用2次vb程序_onresume 调用2次_jsp调用js方法调用

再来说说切屏生命周期状况Android 系统在Activity 生命周期中加入一些钩子,我们可以在很多平台预留的钩子中做一些事情。例举了 7 个常用的钩子:protected void onCreate(Bundle savedInstanceState)protected void onStart()protected void onResume()protected void onPause()protected void onStop()protected void onRestart()protected void onDestroy()简要说明:onCreate(Bundle savedInstanceState):创建activity时读取。设置在该办法中,还以Bundle中可以强调用于建立该 Activity 所需的信息。onStart():activity变为在屏幕上对用户可见时,即获取焦点时,会调用。onResume():activity开始与用户交互时读取(无论是开启还是重新启动一个活动onresume 调用2次,该办法总是被调用的)。onPause():activity被暂停或收回cpu和其他资源时读取,该办法用于储存活动状况的。。onStop():activity被中止并转为不可见阶段及后续的生命周期事件时onresume 调用2次,即丧失焦点时读取。onRestart():重新启动activity时读入。该活动仍在栈中,而不是启动新的活动。onDestroy():activity被完全从平台存储中移除时读取,该办法被调用可能是因为有人直接调用 finish()方法 或者平台决定停止该活动以释放资源。横竖屏切换1 切换到横屏onSaveInstanceStateonPauseonStoponDestroyonCreateonStartonRestoreInstanceStateonResume2 切换到竖屏,销毁了两次onSaveInstanceStateonPauseonStoponDestroyonCreateonStartonRestoreInstanceStateonResumeonSaveInstanceStateonPauseonStoponDestroyonCreateonStartonRestoreInstanceStateonResume

3 修改AndroidManifest.xml,把该Activity添加 android:configChanges="orientation",切横屏,只销毁一次。

onSaveInstanceStateonPauseonStoponDestroyonCreateonStartonRestoreInstanceStateonResume

同时调用2次vb程序_onresume 调用2次_jsp调用js方法调用

4再切回竖屏,发现不会再打印相同信息,但多打印了一行onConfigChanged

onSaveInstanceStateonPauseonStoponDestroyonCreateonStartonRestoreInstanceStateonResumeonConfigurationChanged

5 更改 android:configChanges="orientation" 改成 android:configChanges="orientation|screenSize",切横屏,就只打印onConfigChanged

同时调用2次vb程序_onresume 调用2次_jsp调用js方法调用

onConfigurationChanged

6 切回竖屏

onConfigurationChangedonConfigurationChanged

同时调用2次vb程序_jsp调用js方法调用_onresume 调用2次

总结:

1、不设定Activity的android:configChanges时,切屏会从新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次

2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次

3、设置Activity的android:configChanges="orientation|screenSize"时,切屏不会重新读取各个生命周期,只会执行onConfigurationChanged方法。(执行这个方式,必须设定sdk version 大于等于13.0)


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-120007-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      • 何凯凯
        何凯凯

        升级后信号只有一格

      • 马艺方
        马艺方

        中央军委立即宣布进入南海进行军事演习

      • 常理
        常理

        像这种走秀模式

      热点图片
      拼命载入中...