Chralt
Chralt

Reputation: 67

AS: Hand over points to GameOverActivity

I´ve got one GameActivity and one GameOverActivity. I saved the points of my game in my GameActivity, but will show up these in my GameOverActivity. What I have to do? My gameActivity:

 public void finishGameActivity(){
    Intent intent = new Intent(this, GameOverActivity.class);
    intent.putExtra("points", points);
    Intent i = getIntent();
    setResult(Activity.RESULT_OK, i);
    finish();
 }

 public void setPoints(){
    points++;
    TextView points_show = (TextView) findViewById(R.id.points);
    points_show.setText("Points: " + points);
}


public class GameOverActivity extends AppCompatActivity {
private int points;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game_over);
    changeFont();
    TextView points = (TextView) findViewById(R.id.point_stats);
}

private void changeFont(){
    TextView gameover = (TextView) findViewById(R.id.gameover);
    Typeface custom_font = Typeface.createFromAsset(getAssets(),  
"fonts/font.ttf");
    gameover.setTypeface(custom_font);
}
}

Upvotes: 0

Views: 30

Answers (1)

You could use sharedPreferences to save your current score globally. Else if you just want to pass the score with an intent, use .GetExtras() in the target intent

Upvotes: 1

Related Questions