手柄连接断开时, 后台运行的activity被重新加载
2016-05-03 20:42
302 查看
今天遇到了一个问题,手机连接手柄和断开连接时, activity被重新create, 里面的数据出现了错误,结果界面异常。
原因分析: 在manifest中没有声明相应的config, 导致在系统没有调用onConfigurationChanged, 而是destroy掉了activity,
让我们来看看api中是怎么说的:
所以需要在manifest中添加属性:
原因分析: 在manifest中没有声明相应的config, 导致在系统没有调用onConfigurationChanged, 而是destroy掉了activity,
让我们来看看api中是怎么说的:
* Called by the system when the device configuration changes while your * activity is running. Note that this will <em>only</em> be called if * you have selected configurations you would like to handle with the * {@link android.R.attr#configChanges} attribute in your manifest. If * any configuration change occurs that is not selected to be reported * by that attribute, then instead of reporting it the system will stop * and restart the activity (to have it launched with the new * configuration).
所以需要在manifest中添加属性:
android:configChanges="keyboard|keyboardHidden"
相关文章推荐
- BZOJ 1025 游戏【置换群】
- 自定义topbar
- 【Git+Source Tree使用教程之二】Branching & Merging
- 设计模式之装饰者模式
- MVC架构学习之Smarty学习——病来而蔫
- 山东省第二届ACM大学生程序设计竞赛 Crack Mathmen 打表 模拟
- URAL 1091 Tmutarakan Exams (DP或容斥)
- N
- Linear regression and Normal Equations algorithm
- 共同学习Java源代码--常用工具类--StringBuffer(一)
- Lucene 搜索功能
- JAVA中引用本身占用内存空间的问题
- Java连接mysql中遇到的一些问题及解决方法
- 【连载】关系型数据库是如何工作的?(1) - 前言
- Android学习记录(十) 弹框阻塞处理
- C经典 定义一维数组与二维数组
- Android(1) elipse离线安装adt后,没有图编显示
- css3滤镜-色彩(Chroma)滤镜
- java集合框架
- bat命令中的变量声明及使用