侧边栏壁纸
  • 累计撰写 119 篇文章
  • 累计创建 281 个标签
  • 累计收到 11 条评论
标签搜索
隐藏侧边栏

android fragment屏幕旋转不执行onConfigurationChanged方法

骐骏
2016-02-22 / 0 评论 / 0 点赞 / 295 阅读 / 0 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2016-02-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

自学是一段痛苦的路程。。。。  但我们在痛苦中进步

并不是很困难的问题,但百度n久,各种答案都有,唯独差一个能解决问题的,幸好还有google。在stackoverflow中找到了解决方法。

http://stackoverflow.com/questions/5620033/onconfigurationchanged-not-getting-called

英文原文:

Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

大概其就是 api level 在13及其以上的时候,在AndroidManifest.xml中要配置 android:configChanges="orientation|screenSize".而不仅仅配置android:configChanges="orientation"

ok,问题解决。 此处并不需要配置 <uses-permission android:name="android.permission.CHANGE_CONFIGURATION"></uses-permission>

具体代码可参考:https://github.com/iqijun/fragmetnStudy

 

0

评论区