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 8290537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:50:33+00:00 2026-06-08T12:50:33+00:00

This is more of a Java question as it relates to Android. My code

  • 0

This is more of a Java question as it relates to Android.

My code includes a switch statement with 30 cases. The body of each case has the same format to start an intent relating to that case. I was trying to code the body as a method with the name of the class as an argument, but that code does not compile as the class name has to be hard coded in the intent.

Below is a section of the switch (the long way)

            switch(mState) {
    case 0:
               Intent myIntent = new Intent();
               myIntent.setClass(Home_ASM.this, Home_AS0.class);
               startActivityForResult(myIntent, 0);
               break;

    case 1:
              Intent myIntent1 = new Intent(); 
              myIntent1.setClass(Home_ASM.this, Home_AS1.class);
              startActivityForResult(myIntent1, 2);
              break;    

and I would like to code such:

            switch(mState) {
            case 0:
               myStart(Home_AS0.class,1);
               break;
            case 1:
               myStart(Home_AS1.class,2);
               break;

and the method

private void myStart(String state, int value) {
            Intent myIntent = new Intent();
            myIntent.setClass(Home_ASM.this, state);
            startAcivityForResult(myIntent, value);
            }

Any ideas on how I can make this work?

  • 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-06-08T12:50:34+00:00Added an answer on June 8, 2026 at 12:50 pm

    We do a similar thing. our code looks a bit like this:

    Switch Statement:

    case 0:
          {
             launchActivity(ActivityOne.class, value);
             break;
          }
    

    Method to launch activity:

    private void launchActivity(Class<?> aClass, int value) {
            Intent intent = new Intent();
            intent.setClass(this, aClass);
            startActivityForResult(intent, value);
        }
    

    You can easily adapt this to take your specific int value. Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is more a question of pros/cons between PHP and JAVA. Iv been doing
One more question that relates to this interface . Let's say that I would
I have this following java code skeleton - try { Question q = null;
This is not really a technical programming question, but has more to do with
To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',
Ok, I'm going to try to make this more clear because my last question
This is more of a design question. I have a template class, and I
This question is related to my question on existing coroutine implementations in Java .
I wrote some simple apps in Android using Java. But later I found this:
Sorry for asking this question, but I searched all Java-related questions, but I got

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.