Passing Data between Activities Intent Activity 1 Activity 2 /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"); The Bundle bundleData.putstring("key_age","age"); class provides a container for /Create put the bundle data in the Extra of Intent intent.putExtras(bundleData); storing data /Invoke the activity using the created intent startActivity(intent); 11
Passing Data between Activities 11 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); // Invoke the activity using the created intent startActivity(intent); The Bundle class provides a container for storing data
Bundle The Bundle class provides a container for storing data using a key- value pair(string values to various Parcelable types)mechanism 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 12
Bundle • The Bundle class provides a container for storing data using a keyvalue pair (string values to various Parcelable types) mechanism 12 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