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

  • Home
  • SEARCH
  • 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 7556555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:53:14+00:00 2026-05-30T11:53:14+00:00

I am creating a simple game which after a 5 second timer expires and

  • 0

I am creating a simple game which after a 5 second timer expires and two conditions are checked, condition one is to level up, the intent starts the same activity and I intended to increment my variable level by one every time the player met the condition which increased the game level.

The second condition starts another activity, which is the fail screen.

I didn’t want a different screen for every level up increment, when I can just load the same activity and continue going through the conditions, but as the Activity starts again the level variable resets to its initialised value, the game never leaves level 1. Is there any way to pass a variable a value to an activity when starting it?

Here is the code I have for my Activity:

public class FirstOneActivity extends Activity {
/** Called when the activity is first created. */


MediaPlayer  ourSong;
int counter;
Button add;
Thread timer;
TextView display;
TextView lvl;
int level = 1;
int time;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ourSong = MediaPlayer.create(FirstOneActivity.this, R.raw.click);
    counter = 0;

    add = (Button) findViewById (R.id.bAdd);

    display = (TextView) findViewById (R.id.tvDisplay);
    lvl = (TextView) findViewById (R.id.lvldisplay);




    add.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            counter++;
            //ourSong.start();
            display.setText("Your total is "+ counter);

            if(counter ==1)

            { 

                set();
                timer.start();
            }

        }
    });


     timer = new Thread(){
        public void run(){
            try{
                sleep(time);
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{


                test();


            }
        }


    };

}


public void test(){

 if(counter>= 10 && level == 1 || counter>= 15 && level == 2)
    {    
        Intent openSplash = new Intent("com.deucalion0.FIRSTONE");
        startActivity(openSplash);
        level++;
    }

     else if(counter<10 && level == 1 || counter< 15 && level == 2){

        Intent openNext = new Intent("com.deucalion0.NEXT");
        startActivity(openNext);
    }


}


public void set(){


      if(level == 1)
    {   lvl.setText("Level is "+ level);
        time = 5000;
    }

    else if (level == 2)
    {lvl.setText("Level is "+level);
        time = 5000;
    }



}


}

Any advice is appreciated.

  • 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-30T11:53:16+00:00Added an answer on May 30, 2026 at 11:53 am

    Sure. To put some data in the intent, just use the putExtra method, like so:

    openNext.putExtra("levelNum", 2);
    

    Then in the called Activity, retrieve the bundle of extras and pull out the one you want, like this:

    // in onCreate() method
    int levelNum = getIntent().getExtras().getInt("levelNum");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a simple online multiplayer game, with which two players (clients) can play
I am creating a game in which bubbles with simple math equations are falling
I'm creating a simple pong game.. right now i wanted to set a timer
I'm writing a simple game. I have 3 classes the first one: ball which
I'm creating a basic level editor for a game which is tile based, so
I'm creating a simple labyrinth game with Java + Swing. The game draws a
I'm pretty new to programming, and I'm creating a simple text-based game.> I'm wondering
I'm creating a simple JavaScript multiple choice game. Here is a sample question: p
I've written a simple Scrabble game with a simple Bot and Human part which
I'm creating a simple 3D game on Windows 7 in C++ using the free

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.