java AS:将点数交给GameOverActivity
我有一个游戏活动和一个游戏过度活动。我在GameActivity中保存了游戏点数,但将在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);
}
}
# 1 楼答案
您可以使用SharedReferences全局保存当前分数。否则,如果你只是想有目的地通过分数,使用。目标意图中的GetExtras()