旋轉(zhuǎn)屏幕棋子還是會(huì)消失
代碼如下:
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();
? ?// ?保存游戲內(nèi)部的狀態(tài)保存在 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;
}
// ? 恢復(fù)View ?屏幕旋轉(zhuǎn)后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);
? ? ? ?// ?獲取游戲內(nèi)部INSTANCE中保存的數(shù)據(jù)
? ? ? ?super.onRestoreInstanceState(bundle.getParcelable(INSTANCE));
? ? ? ?return;
? ?}
? ?super.onRestoreInstanceState(state);
}
另外給View 也設(shè)置了id ?
為什么不保存?。?/p>
2016-08-20
id設(shè)置是五子棋的那個(gè)panel要設(shè)置id