user2736219 user2736219 - 1 year ago 84
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?

Answer Source
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()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download