java - How to save your high-score -
java - How to save your high-score -
i want save best, 1 high-score file, , if game on show on menu screen.
like this:
best: points.
i have points , count until die, don't know how save them. heard share preferences. can give me example, best way it. have code checking if points isn't improve best high-score, don't know how save them properly. advise or help appreciated!
here's quick sample, assuming want store , load preferences activity
.
to store values in preferences:
sharedpreferences sharedpreferences = getpreferences(mode_private); sharedpreferences.editor editor = sharedpreferences.edit(); editor.putint("best_score", numberofpoints); editor.commit();
to load value:
sharedpreferences sharedpreferences = getpreferences(mode_private); if (sharedpreferences.contains("best_score")) { // have high score saved, load it... int numberofpoints = sharedpreferences.getint("best_score", -1); // here you'd value, illustration display it. } else { // there no high score value - should hide "best score" textview }
the "best_score"
key under tell android store value - can anything, it's of import key same every time want access/manipulate same value - in case "best score".
java android preferences shared save
Comments
Post a Comment