title: Random next activity button
body: <p>I am really new to coding. So If I explain bad or do dumb mistakes just tell me, so I can get better.</p>
  <p>Anyways. I am creating a game and my intention is to make a button open a random activity.
  Like this:
  activity1 -&gt; activity5 -&gt; activity4 -&gt;activity 18 and so on. Without opening the same activity that has already been played. But now my issue is that I have 20 activities, but sometimes it only appears 12 before my app says &quot;Game Over&quot;. How can I make sure its always gonna load max activites?
  thanx.</p>
  <p>My code works like this:</p>
  <p><strong>Mainactivity.class</strong></p>
  <pre><code>     int r = new Random().nextInt(activitylist.size());
              Class activity = activitylist.remove(r);
  
              switch (r) {
                  case 1:
                      activity = defransman.class;
                      activitylist.remove(defransman.class);
                      break;
                  case 2:
                      activity = crazycaps.class;
                      activitylist.remove(crazycaps.class);
                      break;
                  case 3:
                      activity = max.class;
                      activitylist.remove(max.class);
                      break;
                  case 4:
                      activity = michael.class;
                      activitylist.remove(michael.class);
                      break;
                  case 5:
                      activity = youngest.class;
                      activitylist.remove(youngest.class);
                      break;
                  case 6:
                      activity = driverlincense.class;
                      activitylist.remove(driverlincense.class);
                      break;
  
              }
  
              Intent startgame = new Intent(getBaseContext(), activity);
              startgame.putExtra(&quot;ACTIVITY_LIST&quot;, activitylist);
              startActivity(startgame);
  
          }
      });
  }
  </code></pre>
  <p>}</p>
  <p><strong>Activity2.class:</strong></p>
  <p>public class bestclothes extends AppCompatActivity {</p>
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_bestclothes);
  
      Button nextpage = findViewById(R.id.BTBesteKleren);
      nextpage.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              ArrayList&lt;Class&gt; aktivitet = new ArrayList&lt;&gt;();
              Bundle extras = getIntent().getExtras();
              aktivitet = (ArrayList&lt;Class&gt;) extras.get(&quot;ACTIVITY_LIST&quot;);
  
              if (aktivitet.size() ==0) {
                  Toast.makeText(bestclothes.this, &quot;Game over&quot;, Toast.LENGTH_SHORT).show();
              } else {
                  int r = new Random().nextInt(aktivitet.size());
                  Class activity = aktivitet.remove(r);
  
                  switch (r) {
                      case 1:
                          activity = aktivitet.get(0);
                          aktivitet.remove(0);
                          break;
                      case 2:
                          activity = aktivitet.get(1);
                          aktivitet.remove(1);
                          break;
                      case  3:
                          activity = aktivitet.get(2);
                          aktivitet.remove(2);
                          break;
                      case 4:
                          activity = aktivitet.get(3);
                          aktivitet.remove(3);
                          break;
                      case 5:
                          activity = aktivitet.get(4);
                          aktivitet.remove(4);
                          break;
                      case 6:
                          activity = aktivitet.get(5);
                          aktivitet.remove(5);
                          break;  
  }  
  Intent intent = new Intent(getBaseContext(), activity);
                  intent.putExtra(&quot;ACTIVITY_LIST&quot;, aktivitet);
                  startActivity(intent);
  </code></pre>
  <p>and so on. I</p>