How to give parameters when you run an activity

Asked 2 years ago, Updated 2 years ago, 108 views

Hello, I'm a beginner android developer. I'd like to run an activity that explains the game. I want to include the game ID in that information, but how do I deliver the game ID to the activity? If you don't have a game ID, the game ID is so important that you don't have to show activity. What should I do?

android-activity android oncreate

2022-09-22 22:18

1 Answers

This is an example when id is type int.

Intent intent = new Intent(FirstActivity.this, SecondActivity.class); Bundle b = new Bundle(); b.putInt("key", 1); //1 Put the ID in the part. intent.putExtras(b); //Put ID into int. startActivity(intent); finish(); // If you want to end the current activity and display the explanatory activity, you can add or subtract it.

In the activity describing the game,

Bundle b = getIntent().getExtras(); int value = b.getInt("key");

You can get it like this.


2022-09-22 22:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.