ArtBundleThe Bundle class provides a containerfor storing data using akeyvaluepair(stringvaluestovariousParcelabletypes)mechanismvoid putFloat(Stringkey,float value)// Inserts a float value into the mapping of this Bundle, replacing any existing value for thegiven key.voidputFloatArray(stringkey,float[]value)// Inserts a float array value into the mapping of this Bundle, replacing any existing value forthe given key.void putInt(Stringkey, int value)I/ Inserts an int value into the mapping of this Bundle, replacing any existing value for thegivenkeyvoid putIntArray(string key,int[]value)I/ Inserts an int arrayvalue into the mapping of this Bundle,replacing any existing valueforthe given key.void putstring(string key,Stringvalue)Il Inserts a String value into the mapping of this Bundle, replacing any existing value for thegiven key.voidputstringArray(stringkey,Stringl]value)I/ Inserts a String array value into the mapping of this Bundle, replacing any existing value forthe given key.Classreference:http://developer.android.com/reference/android/os/Bundle.html11
Bundle • The Bundle class provides a container for storing data using a key- value pair (string values to various Parcelable types) mechanism 11 void putFloat(String key, float value) // Inserts a float value into the mapping of this Bundle, replacing any existing value for the given key. void putFloatArray(String key, float[] value) // Inserts a float array value into the mapping of this Bundle, replacing any existing value for the given key. void putInt(String key, int value) // Inserts an int value into the mapping of this Bundle, replacing any existing value for the given key. void putIntArray(String key, int[] value) // Inserts an int array value into the mapping of this Bundle, replacing any existing value for the given key. void putString(String key, String value) // Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key. void putStringArray(String key, String[] value) // Inserts a String array value into the mapping of this Bundle, replacing any existing value for the given key. Class reference: http://developer.android.com/reference/android/os/Bundle.html
Passing Data betweenActivitiesIntentActivity1Activity 2//Create an activity using the constructorIntent intent =new Intent(Activityl.this,Activity2.class)//Create a bundleBundle bundleData= newBundle();I/ Create put string data in the bundle (key-valuepair)bundleData.putstring("key_name""namebundleData.putstring("key_age",,"age");// Create put the bundle data in the Extra of Intentintent.putExtras(bundleData);Il Instead of using bundle, we can also put data, e.g.,strings,directly in the Extra of Intentintent.putExtra("key_id","id");intent.putExtra("key_address","address");// Invoke the activity using the created intentstartActivity(intent);ExMA12
Passing Data between Activities 12 Activity 1 Activity 2 Intent // Create an activity using the constructor Intent intent = new Intent(Activity1.this, Activity2.class); // Create a bundle Bundle bundleData = new Bundle(); // Create put string data in the bundle (key-value pair) bundleData.putString("key_name", "name"); bundleData.putString("key_age", "age"); // Create put the bundle data in the Extra of Intent intent.putExtras(bundleData); // Instead of using bundle, we can also put data, e.g., strings, directly in the Extra of Intent intent.putExtra("key_id", "id"); intent.putExtra("key_address", "address"); // Invoke the activity using the created intent startActivity(intent);