0

I am currently trying to make a 'Higher Or Lower' type game and what I am trying to do is access an integer variable from one Android Activity in another. I have a start page in which the user selects the highest number possible that the computer will be allowed to generate and the app starts a new Activity for the playing of the game. What I would like to do is access the figure the user put in to the start page from the game play page in order to set the maximum figure that the program will generate.

The plan:

Page: Start Page

Ask user what the maximum number they want the computer to generate from a selection of figures on buttons: 10, 25 and 50

Page: Game Play

Takes the value the user selected on the start page to set the highest number the application will generate when performing the random number function

Sorry if I've repeated myself, I just wanted to make sure I was making it clear what I wanted to do.

1 Answer 1

3

You can use the Intent system.

Activity A:

Intent intent = new Intent(A.this, B.class); intent.putExtra("key", "value"); startActivity(intent); 

Activity B:

Intent intent = getIntent(); String value = intent.getStringExtra("key"); 

Refer to this for a better and full explaination :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.