我有一个GameActivity和一个GameOverActivity。我在GameActivity中保存了游戏的分数,但是会在我的GameOverActivity中显示这些分数。我该怎么办? 我的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);
}
}
答案 0 :(得分:1)
您可以使用sharedPreferences全局保存当前分数。否则,如果您只想通过意图传递分数,请在目标意图中使用.GetExtras()