<activity android:name=".Main"
android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
现在笔者正在moto702上测试游戏demo,突然发现滑盖会导致当前Activity多次调用oncreate事件。由于游戏的surfaceview是这里初始化的,所以多次的调用一定会给游戏本身带来多次的初始化。怎么解决呢 在AndroidManifest.xml中修改如上xml的内容android:configChanges="orientation|keyboardHidden"并且在当前Activity中重载方法onConfigurationChanged,有需要的可以在方法中实现自己的功能。如:
/*
*
* if (this.getResources().getConfiguration().orientation ==
* Configuration.ORIENTATION_LANDSCAPE) {
*
* }
*
* else if (this.getResources().getConfiguration().orientation ==
* Configuration.ORIENTATION_PORTRAIT) {
*
* }
*/
本文介绍了解决滑盖手机导致的Android Activity重复初始化问题的方法。通过在AndroidManifest.xml中配置属性并重载onConfigurationChanged方法,可以避免因键盘弹出而引发的游戏SurfaceView多次初始化,确保游戏运行流畅。
4203

被折叠的 条评论
为什么被折叠?



