Tech Talk : Android Programming – Pass Data Between ActivitiesUse this technique to pass variables and values from one Activity to the other.

Sending Value (from existing Activity)
In your current Activity, create a new Intent

Intent i = new Intent(getApplicationContext(), NewActivity.class);
i.putExtra("key","Rabi Was Here");
startActivity(i);


Retrieving Value (in new Activity)
Then in the new Activity, retrieve those values using the following code. You can put this code anywhere, but I normally like to put it in the “onCreate()” function I get my values as soon as I navigate to my new Activity.

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("key");
    Log.d("Test", value);       // Output value of the "key" variable
}

You should get the following output from the code above.

09-16 08:14:18.921 2720-2720/? D/Test: Rabi Was Here

If you are required to transfer an integer from one activity to another, you will have to use the extras.getInt(“new_variable_name”) statement. If you try to get the value via getString(), android returns null.