How to pass a value to an activity from another activity in Android

In starting activity(first activity) write down the following piece of code.

Intent photoDetails = new Intent(this, PhotoDetails.class);
photoDetails.putExtra("id_number", v.getId());

photodetails is the second activity. Add the following piece of code in the photodetails activity to get the value for “id_number”.

Bundle extras = getIntent().getExtras();
int photo_id = extras.getInt("id_number");

No comments: