I'm creating a Highscore, so I have to pass a Int to other acitivity to increment it when a person answer correctly a question. How can I do that?
Asked
Active
Viewed 46 times
1 Answers
1
You can pass int , string or whatever you want using Intent.
String SCORE_TAG = "score";
int highScore = 120;
Intent i = new Intent(CurrentActivity.this, YourActivity.class);
i.putExtra(SCORE_TAG,highScore);
startActivity(i);
And in YourActivity use this.
Intent i = getIntent();
my_score = i.getIntExtra(SCORE_TAG,0); // 0 for default value.

Shashank singh
- 641
- 3
- 14