In my MainActivity
i have a score variable,
int score = 0;
however i have another activity which is the DisplayScore
activity (which displays the score) txtFinalScore.setText("Score: " + score);
how can i use that same variable form my MainActivity
to my DisplayScore
activity so that i can display the score?
2
Answers
If I’ve understood well, here’s how you should do it.
This question explains perfectly how to use
putExtra()
andgetExtra()
methods for the Intent in Android, because I think that’s what you need.Also, if you find this difficult, you can store the score value into a sharedPreference and retrieve it from another activity. You can see the docs here.