Ana Ana - 21 days ago 5
JSON Question

Pass two bundles to same activity

I have a list of json array response with multiple userinformation. Created a bundle and successfully passed it to next activity. Created another bundle with user selected date and time.But no luck to second bundle to the same activity because i can be able to pass only one bundle to same activity.

My actual problem is how to pass second bundle in putExtras to same activity

Json Response
{
"userinfo": [
{
"address": "Tambaram",
"name": "Vishranthi"
},
{
"address": "Medavakkam",
"name": "Sophia"
},
]
}


Bundle creation code:

JSONArray infoarray = obj.getJSONArray("Info");
Bundle h = new Bundle();
for (int i = 0; i < infoarray.length(); i++) {
Bundle b = new Bundle();

JSONObject infoobject = infoarray.getJSONObject(i);
String name = infoobject.getString("name");
String address = infoobject.getString("address");

b.putString("name", name);
b.putString("address", address);

h.putBundle(Integer.toString(i), b);

System.out.println(b);
}
Intent i = new Intent(context, Secondpage.class);
Bundle d=new Bundle();
d.putString("date", text1);
d.putString("time", text2);

i.putExtras(h);
System.out.println(h);
context.startActivity(i);

Answer

if you want to put two bundles into your intent you have to use

Intent putExtra (String name, 
                Bundle value)

something like this:

Intent i = new Intent(context, Secondpage.class);
i.putExtra("bundleH", h);
i.putExtra("bundleD", d);

ref