I have implemented a random activity class to my project in android studio, and I have it set up so that when the activity is shown once it gets removed but for some reason the activity doesn't get removed and it'll show up again and when the activity changes sometimes it will just out of no where change to another activity before the user even does anything. ( When ever I want to change activities I call openRandomActivity(); )
Here's my code for the Random Activity Class:
public class OpenRandomActivities extends Activity {
ArrayList<Class> activities = new ArrayList<>();
//Implement points into this class because you can't extend multiple classes to a single class in android (Not important for this error)
protected static int points;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
activities.add(One.class);
activities.add(Two.class);
activities.add(Three.class);
activities.add(Four.class);
activities.add(Five.class);
}
public void openActivity(Class class_){
Intent intent = new Intent(this, class_);
startActivity(intent);
}
public void openRandomActivity(){
Class that = activities.get(new Random().nextInt(activities.size()));
activities.remove(that);
openActivity(that);
}
}
It would be great if I could get some help on this! Thank you!
Aucun commentaire:
Enregistrer un commentaire