1st way: In your current Activity, when you create object of intent to open new screen:
String value="xyz";
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
intent.putExtra("key", value);
startActivity(intent);
Then in the nextActivity in onCreate method, retrieve those values which you pass from previous activity:
if (getIntent().getExtras() != null) {
String value = getIntent().getStringExtra("key");
//The key argument must always match that used send and retrive value from one activity to another.
}
2nd way: You can create bundle object and put values in bundle and then put bundle object in intent from your current activity -
String value="xyz";
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("key", value);
intent.putExtra("bundle_key", bundle);
startActivity(intent);
Then in the nextActivity in onCreate method, retrieve those values which you pass from previous activity:
if (getIntent().getExtras() != null) {
Bundle bundle = getIntent().getStringExtra("bundle_key");
String value = bundle.getString("key");
//The key argument must always match that used send and retrive value from one activity to another.
}
You can also use bean class to pass data between classes using serialization.