To send an integer value from one activity to another in Android, you can use an intent and put the integer as an extra. Here is an example:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class); intent.putExtra("key", 123); startActivity(intent);
int value = getIntent().getIntExtra("key", 0);
The second parameter of the getIntExtra
method is the default value, which will be used if the extra is not found.
You can also use other types of data, such as strings or arrays, by using the corresponding putExtra
and getExtra
methods. For example, to send a string, you can use putExtra("key", "value")
and to retrieve it, you can use getStringExtra("key")
.