user2736219 user2736219 - 9 months ago 37
Android Question

Passing random generated integers to an intent

How to take a random generated integer and pass it to another Activity?

I have worked with Intents before, however since I never see the value of the integer, I cannot specify.


int w = numGen.nextInt(7);

How do I put
into the Intent and use it in another Activity?

Intent intent = new Intent(this, AnotherActivity.class);
intent.putExtra("myrandom", yourRandomVal);
startActivity(this, intent);

In your other activity's onCreate():

int passedRandom = getIntent().getIntExtra("myrandom");

The thing is you can add extras to an intent by using various putExtra() and then get it using getExtra()