旋轉屏幕棋子還是會消失
代碼如下:
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 ?
為什么不保存啊?
2016-08-20
id設置是五子棋的那個panel要設置id