@Override
public Object onRetainNonConfigurationInstance(){
final TicTacToeGame game = collectData();
return game;
}
private TicTacToeGame collectData(){
return mGame;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBoardButtons = new Button[TicTacToeGame.getBOARD_SIZE()];
mBoardButtons[0] = (Button) findViewById(R.id.one);
mBoardButtons[1] = (Button) findViewById(R.id.two);
mBoardButtons[2] = (Button) findViewById(R.id.three);
mBoardButtons[3] = (Button) findViewById(R.id.four);
mBoardButtons[4] = (Button) findViewById(R.id.five);
mBoardButtons[5] = (Button) findViewById(R.id.six);
mBoardButtons[6] = (Button) findViewById(R.id.seven);
mBoardButtons[7] = (Button) findViewById(R.id.eight);
mBoardButtons[8] = (Button) findViewById(R.id.nine);
mInfoTextView = (TextView) findViewById(R.id.information);
mHumanScoreTextView = (TextView) findViewById(R.id.player_score);
mComputerScoreTextView = (TextView) findViewById(R.id.computer_score);
mTieScoreTextView = (TextView) findViewById(R.id.tie_score);
mGame = new TicTacToeGame();
startNewGame();
final TicTacToeGame game = (TicTacToeGame)getLastNonConfigurationInstance();
if (game == null)
{
game = collectData();
}
當設備方向從縱向切換到景觀,Layout
加載罰款,但沒有被保存,分數被重置意義的所有數據都將丟失。 game = collectData();
部分以及要求我刪除最終修改器上
final TicTacToeGame game = (TicTacToeGame)getLastNonConfigurationInstance();
任何想法??