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