Reputation: 77
I am trying to compare 2 scores that I have made lastScore and best_score(both in Main_Screen). If lastScore is higher than bestScore I want it to change the best_score to the lastScore.There are no errors but if the lastScore is lower than best_score, I don't want it to change. The only problem is that the score changes regardless of whether the lastScore is higher or lower. Thanks in advance.
https://github.com/alex578344/FirstApp
Upvotes: 1
Views: 75
Reputation: 2881
As @Apurva said, you have to use the shared Preferences like this:
public void saveInfo(int bestScore) {
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("BEST_SCORE", bestScore);
}
public int retrieveInt() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
return sp.getInt("BEST_SCORE", 0);
}
Upvotes: 2