How to Randomly Goto the Next Activity?

0 kayden rice · October 14, 2015
I'm making an app that needs a way to get to the next activity(s) randomly. Anyone have a way to do so?
I need it so I'll be able to randomly start the activity(s) by clicking a button, and/or in and "if" statement.

This would be extremely great help! Thank you.

Post a Reply

Replies

Oldest  Newest  Rating
0 Wojtek Gołąb · October 15, 2015
You can try this one: 

Random r = new Random();

switch (r.nextInt(10))
{
     case 0: Intent i = new Intent(this, myActivity.class);
     case 1: Intent i = new Intent(this, mySecondActivity.class);
     case 2: Intent i = new Intent(this, myThirdActivity.class);
    .....
    .....
}

argument in method nextInt tells us the highest number that can be randomly selected :)
I hope it will help you.
0 Gary Whitney · October 14, 2015
How does this sound?

Java has a Random object with next int method for generating integers within a range.
So your range would be the number of activities.
Then use a Switch/Case structure to generate the intent for a specific activity.
  • 1

Java / Android Development

107,214 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator