java - : Hand over points to GameOverActivity

标签 java android android-studio android-activity points

我有一个 GameActivity 和一个 GameOverActivity。我将游戏积分保存在 GameActivity 中,但会在 GameOverActivity 中显示这些积分。我必须做什么? 我的游戏 Activity :

 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);
}
}

最佳答案

您可以使用sharedPreferences全局保存您当前的分数。否则,如果您只想通过 Intent 传递分数,请在目标 Intent 中使用 .GetExtras()

关于java - : Hand over points to GameOverActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48469237/

相关文章:

java - 使用 xstream 将 XML 映射到 POJO

Android:无法加载库(94 缺少基本表)

android - 位置管理器 : java. lang.NoSuchMethodError

java - 在 Grails 中发布嵌套资源的问题

java - 在 Oreo 中识别短信号码 ID

java - Xml 签名在添加 c14n 独占转换时无效

Android - 无法卸载应用程序

android - 来自 Couchbase Lite 的 React-Native Android 图像源

android - 在目录 React Native 中找不到已签名的 Apk - Android

java - 添加特定 jar 时出现 "app:preDexDebug"错误