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

今天遇到了一个问题,手机连接手柄和断开连接时, 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"




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值