Can someone kindly give me a solution to this and explain how he/she came to that particular solution?
Thanks so much
1) Upon rotation of the GUI from portrait to landscape or the opposite disappears all local variables.Write content of the class, where it is marked with To-Do, so that variable isGameFinished taken care of by rotation and collected again when the app is rotated
Class
public class StatteActivity extends Activity{
private boolean isGameFinished;
private Button buttonFinishGame;
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_state);
//Get previous state for isGameFinished if it exists
//TO-DO
//Find button
buttonFinishGame = (Button) findViewByID(R.id.buttonFinishGame);
buttonFinishGame.setOnClickListener(new OnClickListener(){
public void onClick(View v){
isGameFinished = true;
}
});
if(isGameFinished){
finish();
}
}
protected void onSaveInstanceState(Bundle outState){
//To-Do
super.onSaveInstanceState(outState);
}
}
Copyright Notice:Content Author:「user2709498」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18394274/how-to-save-and-retrieve-variables-upon-screen-rotation