android 横竖屏旋转Activity生命周期变化(面试)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fsc_fantexi/article/details/88813500

题目:android 横竖屏旋转Activity生命周期如何变化?

上网查询:

android:screenOrientation=""

常用的属性:

  • unspecified,默认值,由系统决定,不同手机可能不一致
  • landscape,强制横屏显示
  • portrait,强制竖屏显
  • behind,与前一个activity方向相同
  • sensor,根据物理传感器方向转动,用户90度、180度、270度旋转手机方向,activity都更着变化
  • sensorLandscape,横屏旋转,一般横屏游戏会这样设置
  • sensorPortrait,竖屏旋转
  • nosensor,旋转设备时候,界面不会跟着旋转。初始化界面方向由系统控制
  • user,用户当前设置的方向

(链接:https://www.cnblogs.com/amyzhu/p/8271368.html)

android:configChanges=""
  VALUE DESCRIPTION 
mcc 国际移动用户识别码所属国家代号是改变了,sim被侦测到了,去更新mcc    MCC是移动用户所属国家代号
mnc 国际移动用户识别码的移动网号码是改变了, sim被侦测到了,去更新mnc    MNC是移动网号码,最多由两位数字组成,用于识别移动用户所归属的移动通信网
locale 用户所在区域发生变化,一般是用户切换了语言时,切换后的语言会显示出来
touchscreen 触摸屏是改变了------通常是不会发生的
keyboard 键盘发生了改变----例如用户用了外部的键盘
keyboardHidden 键盘的可用性发生了改变
navigation 导航发生了变化-----通常也不会发生
screenLayout 屏幕的显示发生了变化------不同的显示被激活
fontScale 字体比例发生了变化----选择了不同的全局字体
uiMode 用户的模式发生了变化
orientation 屏幕方向改变了---横竖屏切换
screenSize 屏幕大小改变了
smallestScreenSize 屏幕的物理大小改变了,如:连接到一个外部的屏幕上

 (链接:https://blog.csdn.net/lkk790470143/article/details/79345971)

开始调试:

默认
onPause():
onSaveInstanceState():
onStop():
onDestroy():
onCreate():
onStart():
onRestoreInstanceState():
onResume():

配置
android:configChanges="orientation"
只调用onConfigurationChanged(Configuration newConfig)方法

配置
android:configChanges="screenSize"
android:configChanges="keyboardHidden"
(默认效果是一样)
onPause():
onSaveInstanceState():
onStop():
onDestroy():
onCreate():
onStart():
onRestoreInstanceState():
onResume():

组合
android:configChanges="orientation|screenSize" //(screenSize|orientation效果一样)
android:configChanges="orientation|keyboardHidden" //(keyboardHidden|orientation效果一样)
只调用onConfigurationChanged(Configuration newConfig)方法

android:configChanges="screenSize|keyboardHidden" //(keyboardHidden|screenSize一样)
onPause():
onSaveInstanceState():
onStop():
onDestroy():
onCreate():
onStart():
onRestoreInstanceState():
onResume():

android:configChanges="keyboardHidden|screenSize|orientation"
android:configChanges="screenSize|orientation|keyboardHidden"
android:configChanges="orientation|screenSize|keyboardHidden"
只调用onConfigurationChanged(Configuration newConfig)方法

总结:

android:screenOrientation="unspecified“,默认值,由系统决定,不同手机可能不一致

android:screenOrientation和android:configChanges=”orientation“会相互影响

默认情况下:旋转屏幕(横竖屏)activity生命周期onPase()->onSaveInstanceState()->onStop->onDestory()->onCreate()->onStart()->onRestoreInstanceState()->onResume()

配置android:configChanges="orientation"
只调用onConfigurationChanged(Configuration newConfig)方法

猜你喜欢

转载自blog.csdn.net/fsc_fantexi/article/details/88813500