I'm creating a simple android game but I'm not sure what I'm doing wrong here due to being new to android. The first bit of code I have is in the GameView class and returns an integer for how many times a sprite is pressed:
public int getHitCount() {
return hitCount;
}
It is then returned to the GameActivity class where an intent receives it and then it is supposed to go to the main menu class, I think I've got it being sent to the GameActivity class correctly but I'm not sure why the score is not returned to the main menu. Here is my GameActivity intent:
public void finish(){
super.finish();
Intent returnIntent = new Intent(GameActivity.this,MainMenu.class);
returnIntent.putExtra("GAME_SCORE",gameView.getHitCount());
setResult(RESULT_OK, returnIntent);
}
}
Here is the code I use to display it on the MainMenu class but it isn't working for some reason:
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));
}
}
Aucun commentaire:
Enregistrer un commentaire