android - Shared Preferences saving an int? -
i saw on stack need save high score android game
this told me
//setting preferences sharedpreferences prefs = this.getsharedpreferences("myprefskey", context.mode_private); editor editor = prefs.edit(); editor.putint("key", score); editor.commit(); //getting preferences sharedpreferences prefs = this.getsharedpreferences("myprefskey", context.mode_private); int score = prefs.getint("key", 0); //0 default value i wondering, should "key" string highscore located? , matter name prefs key. time.
the android developers documentation excellent place start question this. sharedpreferences can found here. sharedpreferences simple key-value pair storage, if put int shared preferences key "high score", in future, if want int, need use prefs.getint("high score"). doesn't matter name keys, practice use private static final string variables store keys use on regular basis.
Comments
Post a Comment