I can't really explain what I'm trying to say through the title, but I'll expand here.
Anyway, I'm still learning how to code so pardon my misuse of a few terms.
I made a simple app that displays an array of strings. It features just two visual parts- a TextView element and a Button element. Pressing the button displays a random fruit from the String Array.
Thing is, when I change orientations, the displayed fruit changes. I know that this happens because the activity is 'remade' whenever the orientation is changed. And I do have an understanding on how to use onSaveInstanceState and its counterpart.
But I have no idea how to save and restore the currently-displayed value in the Display because I'm using Random instead of int. Because of this, I don't think I can rely on using putInt and getInt.
TextView Display;
Button randomize;
String[] fruitArray;
Random counter = new Random();
Random rand = new Random();
int launchCounter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeButtons();
checkAndroidVersion();
changeFont();
fruitArray= getResources().getStringArray(R.array.fruits);
launchCounter = rand.nextInt(10) + 1;
Display.setText(fruitArray[launchCounter]);
randomize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
int maxIndex = jokeArray.length;
int generatedIndex = counter.nextInt(maxIndex);
Display.setText(fruitArray[generatedIndex]);
}
});