我如何从一个 activity 检索 int 数据并将其设置为另一个 activity 的 textView

How can i retrieve int data from one activity and set it to textView of another activity

发送class代码:

Intent i = new Intent(this, QuizActivity.class);
        i.putExtra("name", name);
        startActivity(i);

收到 class 代码:

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