您的位置:首页 > 其它

手柄连接断开时, 后台运行的activity被重新加载

2016-05-03 20:42 302 查看
今天遇到了一个问题,手机连接手柄和断开连接时, activity被重新create, 里面的数据出现了错误,结果界面异常。

原因分析: 在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"





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: