发送类代码:
Intent i = new Intent(this, QuizActivity.class);
i.putExtra("name", name);
startActivity(i);
接收类代码:
Intent intent = getIntent();
if (intent != null) {
totalScore = intent.getIntExtra("totalScore",0);
}
TextView scoreView = findViewById(R.id.totalScore);
scoreView.setText(totalScore);
在发送端,使用 Intent.putExtra:
Intent myIntent = new Intent(A.this, B.class);
myIntent.putExtra("totalScore", intValue);
startActivity(myIntent);
在接收端,使用 Intent.getIntExtra:
Intent mIntent = getIntent();
int totalScore = mIntent.getIntExtra("totalScore", 0);
TextView scoreView = findViewById(R.id.totalScore);
scoreView.setText(totalScore+"");