Get Your 100% Free IQ Test Android App
How to pass data to another activity in Android Studio?

How to pass data to another activity in Android Studio?

passing additional data when opening a new activity using intent

Inside your MainActivity.java file, locate onCreate() method or create a new public method for onClick event and put the code below inside it:

Intent intent = new Intent(getApplicationContext(), AnotherActivity.class);

intent.putExtra("key1","value1");
intent.putExtra("key2","value2");
intent.putExtra("key3","value3");
 
startActivity(intent);//start intent..

this will open another activity and send additional values by putExtra() method. 

 

in order to receive these values, go to AnotherActivity.java file, locate onCreate() method and use this code to retrieve data:

Intent intent = getIntent();

String value1 = intent.getStringExtra("key1");
String value2 = intent.getStringExtra("key2");
String value3 = intent.getStringExtra("key3");