@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();
任何想法??