I am making a simple game for android, however as I am kind of beginner sometimes I have some problems with basic things and errors in my code. I dont know what is wrong with that code but it seems to crash when I press back button and does not redirect the score from game to main menu.
public void finish(){
Intent returnIntent = new Intent();
returnIntent.putExtra("GAME_SCORE",gameView.getHitCount());
setResult(RESULT_OK, returnIntent);
super.finish();
}
GameView:
public int getHitCount(){
return hitCount;
}
and MainMenu:
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));
}
}
}
}