I have a problem with my activity. This is my onCreate:
case NORMAL:
game = new Game(); // create new game
game.initializeGame(); // initialize new game
addSomeElements(result); // add elements to array due to user choice
game.getCurrentLevel().nextPair(); // next pair of elements from array
pictureGameLeft
.setImageResource(colorsPictures.get(game.getCurrentLevel().getCurrentPair().getImageLeft()));
pictureGameRight.setImageResource(colorsPictures.get(game.getCurrentLevel().getCurrentPair()
.getImageRight()));
break;
case NOTNORMAL:
game = new Game();
game.initializeGame();
addSomeElements(result);
game.getCurrentLevel().nextPair();
pictureGameLeft
.setImageResource(shapesPictures.get(game.getCurrentLevel().getCurrentPair().getImageLeft()));
pictureGameRight.setImageResource(shapesPictures.get(game.getCurrentLevel().getCurrentPair()
.getImageRight()));
break;
This is create new game due to user choice. When user choice NORMAL to arraylist “normal” will be add some elements. If user choice NOTNORMAL to arraylist “notnormal” will be add other elements. After that I get pair of elements from this arraylist and shows images.
Now this is my problem. When I choose any option, the game is create and shows two images. When I lock my phone and after that, unlock, I get other pictures. I think that my onCreate method is started again. I want to save first images and when I lock and unlock my phone I get the same pictures. How I can do this. I try use this solution after onCreate:
@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putIntegerArrayList("table", (ArrayList<Integer>) normal);
super.onSaveInstanceState(savedInstanceState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
ArrayList<Integer> normal = savedInstanceState.getIntegerArrayList("table");
}
but it’s not working.
edit1:
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
ArrayList<Integer> normal = savedInstanceState.getIntegerArrayList("table");
pictureGameLeft.setImageResource(normal.get(game.getCurrentLevel().getCurrentPair().getImageLeft()));
pictureGameRight.setImageResource(normal.get(game.getCurrentLevel().getCurrentPair().getImageRight()));
after doing that you need to use those values too… I mean what ever you are doing in that switch case… do the same again