旋转屏幕棋子还是会消失
代码如下:
private static final String INSTANCE = "instance";
private static final String INSTANCE_GAMEOVER = "instance_gameover";
private static final String INSTANCE_WHITE_ARRAY = "instance_black_array";
private static final String INSTANCE_BLACK_ARRAY = "instance_white_array";
// 保存view
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
// 保存游戏内部的状态保存在 INSTANCE 中
bundle.putParcelable(INSTANCE,super.onSaveInstanceState());
bundle.putBoolean(INSTANCE_GAMEOVER,mIsGameOver);
bundle.putParcelableArrayList(INSTANCE_WHITE_ARRAY,mWhiteArray);
bundle.putParcelableArrayList(INSTANCE_BLACK_ARRAY,mBlackArray);
return bundle;
}
// 恢复View 屏幕旋转后View 不变
@Override
protected void onRestoreInstanceState(Parcelable state) {
if(state instanceof Bundle){
Bundle bundle = (Bundle) state;
mIsGameOver = bundle.getBoolean(INSTANCE_GAMEOVER);
mWhiteArray = bundle.getParcelableArrayList(INSTANCE_WHITE_ARRAY);
mBlackArray = bundle.getParcelableArrayList(INSTANCE_BLACK_ARRAY);
// 获取游戏内部INSTANCE中保存的数据
super.onRestoreInstanceState(bundle.getParcelable(INSTANCE));
return;
}
super.onRestoreInstanceState(state);
}
另外给View 也设置了id
为什么不保存啊?