I have an app which displays the score on the main screen but this sets to zero every time a new game is started. What I want it to do is store that score and only change if the next score is higher, hence it being the highest score.
At the moment a hitCount method is deployed which a finish() method utilises to show the score from the game activity to the main activity.
The finish() method is below:
public void finish(){
Intent returnIntent = new Intent();
returnIntent.putExtra("GAME_SCORE", gameView.getHitCount());
setResult(RESULT_OK, returnIntent);
super.finish();
}
In the MainMenu class, the following onActivityResult() method is used to get the score to display on the main screen:
protected void onActivityResult(int requestCode, int resultCode, Intent retIntent) {
// Check which request we're responding to
if (requestCode == SCORE_REQUEST_CODE) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
if (retIntent.hasExtra("GAME_SCORE")) {
int scoreFromGame = retIntent.getExtras().getInt("GAME_SCORE");
tvScore.setText(Integer.toString(scoreFromGame));
//highScore.setText(Integer.toString(scoreFromGame));
}
}
}
}
Now, I know I must use something like shared preference to have any chance of storing the score and replacing it with a higher number when achieved but I can't figure out how and where.
As always, any help greatly appreciated.
Thanks