0

Sending class code:

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

Recieving class code:

Intent intent = getIntent();
    if (intent != null) {
        totalScore = intent.getIntExtra("totalScore",0);
    }
    TextView scoreView = findViewById(R.id.totalScore);
    scoreView.setText(totalScore);
  • i think parameter name is not set only name is set in intent and on receiving side code is expecting totalScore in intent. – Shahid Farooq May 31 '20 at 15:44

1 Answers1

0

On the sender side, use Intent.putExtra:

Intent myIntent = new Intent(A.this, B.class);
myIntent.putExtra("totalScore", intValue);
startActivity(myIntent);

On the receiver side, use Intent.getIntExtra:

 Intent mIntent = getIntent();
 int totalScore = mIntent.getIntExtra("totalScore", 0);
 TextView scoreView = findViewById(R.id.totalScore);
 scoreView.setText(totalScore+"");
Shalu T D
  • 3,921
  • 2
  • 26
  • 37