[Solved] Android Code – Radom number generation for calling activity [duplicate]


myBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            Random r = new Random();
            int index = r.nextInt(4)+1;

            Intent intent;

            if (index == 4) {
                intent = new Intent(Activity.this, Activity4.class); 
            }
            else if (index == 3) {
                intent = new Intent(Activity.this, Activity3.class); 
            }
            else if (index == 2) {
            intent = new Intent(Activity.this, Activity2.class); 
            }
            else 
            intent = new Intent(Activity.this, Activity1.class);                    

            startActivity(intent);                
         }
    });

4

solved Android Code – Radom number generation for calling activity [duplicate]