我正在android studio上开发简单的游戏,你需要识别给定的图像。每张图片有40分,但每次你回答错误时,你的40分将被扣除10分。积分将累积,直到您完成识别10张图片。我的问题是,我不知道如何将积分传递给另一个活动,以便我可以添加它。这是我的Java代码.. PS。抱歉,我在android studio和StackOverflow中都是新手,我不知道如何撰写问题。
public void onClickSubmit (View view) {
answer = (EditText) findViewById(R.id.etAnswer);
tvResult = (TextView) findViewById(R.id.resultLabel);
if (answer.getText().toString().equals("apple")) {
Intent intent = new Intent(this, appleTrivia.class);
startActivity(intent);
tvResult.setText("Good eye sight");
tvResult.setTextColor(0xFF00FF00);
timer.cancel();
totalScorePoints = scorePoints;
String result = String.valueOf(totalScorePoints);
pointsLabel.setText("Score: " + result);
answer.setText("");
} else {
tvResult.setText("No no no. try again.");
tvResult.setTextColor(0xFFFF0011);
answer.setText("");
scorePoints = scorePoints - minusPoint;
totalScorePoints = scorePoints;
String result = String.valueOf(totalScorePoints);
pointsLabel.setText("Score: " + result);
如何将totalScorePoint传递给我的第二个活动,以便将第一个活动的点数添加到第二个活动的点数。 tnx将响应我的noob问题^ _ ^这是我的第二个活动.enter code here here public void onClickSubmit(查看视图){
answer = (EditText) findViewById(R.id.etAnswer);
tvResult = (TextView) findViewById(R.id.resultLabel);
if (answer.getText().toString().equals("cherry")) {
Intent intent = new Intent(this, cherryTrivia.class);
startActivity(intent);
tvResult.setText("Good eye sight");
tvResult.setTextColor(0xFF00FF00);
timer.cancel();
totalScorePoints = scorePoints;
String result = String.valueOf(totalScorePoints);
pointsLabel.setText("Score: " + result);
answer.setText("");
} else {
tvResult.setText("No no no. try again.");
tvResult.setTextColor(0xFFFF0011);
answer.setText("");
scorePoints = scorePoints - minusPoint;
totalScorePoints = scorePoints;
String result = String.valueOf(totalScorePoints);
pointsLabel.setText("Score: " + result);
}
}
}
<!-- end snippet -->
答案 0 :(得分:3)
在发送方:
Intent intent = new Intent(this, cherryTrivia.class);
intent.putExtra( "points", scorePoints );
startActivity(intent);
在接收方:
getIntent().getIntExtra( "points", 0 );