What\'s the correct way to pass a bundle to the activity that is being launched from the current one? Shared properties?
Passing data from one Activity to Activity in android
An intent contains the action and optionally additional data. The data can be passed to other activity using intent putExtra()
method. Data is passed as extras and are key/value pairs
. The key is always a String. As value you can use the primitive data types int, float, chars, etc. We can also pass Parceable and Serializable
objects from one activity to other.
Intent intent = new Intent(context, YourActivity.class);
intent.putExtra(KEY, );
startActivity(intent);
Retrieving bundle data from android activity
You can retrieve the information using getData()
methods on the Intent object. The Intent object can be retrieved via the getIntent()
method.
Intent intent = getIntent();
if (null != intent) { //Null Checking
String StrData= intent.getStringExtra(KEY);
int NoOfData = intent.getIntExtra(KEY, defaultValue);
boolean booleanData = intent.getBooleanExtra(KEY, defaultValue);
char charData = intent.getCharExtra(KEY, defaultValue);
}