Android Save High Scores
What's up guys I'm developing a game for Android and I have one problem
that I didn't find in internet.I want to save the highscore with
sharedprefferences and that is the code: Play Class : SharedPreferences
prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
Editor edit = prefs.edit(); edit.putInt("key", score); edit.commit();
Toast.makeText(getApplicationContext(), "SAVED",
Toast.LENGTH_LONG).show();
Intent it = new Intent(getApplicationContext(),HighScore.class);
startActivity(it);
And this is the highscore list code :
highscore = (TextView) findViewById(R.id.highscore_int); SharedPreferences
prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE); int
score = prefs.getInt("key", 0); //0 is the default value
highscore.setText(""+score);
This works fine but it saves all scores even it's small than previous.I
want to save the score only if it's bigger than previous.How can I do that
? PS : Sorry for my English and I don't know how to highlight the code :(
No comments:
Post a Comment