Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7091159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:08:56+00:00 2026-05-28T08:08:56+00:00

If I have 3 activities, how would I set up a randomise between the

  • 0

If I have 3 activities, how would I set up a randomise between the activities so it picks one out of the three and displays that?

So far I have tried the following code:

package com.ICTrevisionapp;

import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class randomquiz extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        // TODO Auto-generated method stub 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.quiz);  
        Button generate = (Button)findViewById(R.id.generate); 
        generate.setOnClickListener(generateListener); 
    } 
    private OnClickListener generateListener = new OnClickListener() { 
        public void onClick(View v){ 
            Random generator = new Random(); 
            int number = generator.nextInt(2); 
            Intent intent = null; 
            switch(number){ 
            case 0: 
            intent = new Intent(randomquiz.this, topicstotopicone.class); 
            break; 
            case 1: 
            intent = new Intent(randomquiz.this, topicstotopictwo.class); 
            break; 
            case 2: 
            intent = new Intent(randomquiz.this, topicstotopicthree.class); 
            break; 
            } 
            startActivity(intent); 
        }
};
}

Is this also correct for the manifest :

  <activity
        android:name=".randomquiz"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.topicstotopicone" />
            <action android:name="android.intent.action.topicstotopictwo" />
            <action android:name="android.intent.action.topicstotopicthree" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity

However this runs the application but when the button is pressed, nothing is acomplished.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:08:57+00:00Added an answer on May 28, 2026 at 8:08 am

    your code does not make much sense . it would be enough to do this:

    public void onClick(View v){
        Random generator = new Random();
        int number = generator.nextInt(3);
        Intent intent = null;
        switch(number){
        case 0:
        intent = new Intent(randomquiz.this, topicstotopicone.class);
        break;
        case 1:
        intent = new Intent(randomquiz.this, topicstotopictwo.class);
        break;
        case 2:
        intent = new Intent(randomquiz.this, topicstotopicthree.class);
        break;
        }
        startActivity(intent);
    }
    

    Your Activities will also have to be declared in your Android Manifest.xml:

    <activity
        android:name=".randomquiz"
        android:label="@string/app_name" >
        <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".topicstotopicone"
        android:label="@string/app_name"
    </activity>
    <activity
        android:name=".topicstotopictwo"
        android:label="@string/app_name"
    </activity>
    <activity
        android:name=".topicstotopicthree"
        android:label="@string/app_name"
    </activity>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following layout defined for one of my Activities: <?xml version=1.0 encoding=utf-8?>
I have a set of GIT repositories that I always have different activities on
I have three activities: Activity A - Displays a list of data from a
I have a XAML form that I would like two independent features threaded out
In my application I have several activities, the main screen has 4 buttons that
I have a sequential workflow with a number of Activities. One of these activities
I have a bunch of Workflow foundation 4.0 RC code activities that consume web
I have a WF service that I'm trying to setup receive activities to Subscribe
Is it possible to have a split screen that would have a camera preview
I have two activities one displaying map view and another listview, the main objective

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.