Reputation: 323
I want to send the arraylist with hashmap between activities but is give me null arraylist with hashmap.
Sender Activity
ArrayList<HashMap<String,String>> childgame = new ArrayList<HashMap<String,String>>();
Intent ordernow= new Intent(CategoryActivity.this,OrderDetailActivity.class);
ordernow.putExtra("orderlist",childgame);
startActivity(ordernow);
Receiver Activity
Intent intent = getIntent();
Bundle bundle =intent.getExtras();
bundle.getSerializable("orderlist");
Upvotes: 1
Views: 5015
Reputation: 133560
Use putExtra(String, Serializable)
to pass the value in an Intent and getSerializableExtra(String)
method to retrieve the data.
ArrayList implements Serializable
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
You already have this
ordernow.putExtra("orderlist",childgame);
To get the list
Intent intent = getIntent();
ArrayList<HashMap<String,String>> list = (ArrayList<HashMap<String, String>>) intent.getSerializableExtra("orderList");
public Serializable getSerializableExtra (String name)
Added in API level 1
Retrieve extended data from the intent.
Parameters
name The name of the desired item.
Returns
the value of an item that previously added with putExtra() or null if no Serializable value was found.
Upvotes: 6
Reputation: 14199
try by using getIntent().getSerializableExtra("orderlist")
on Receiver side use : same type of ArrayList to receive data !
ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("orderlist");
Upvotes: 1