如何从一个活动中检索 int 数据并将其设置为另一个活动的 textView



发送类代码:

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+"");

最新更新