1

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");
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
start android
  • 323
  • 7
  • 21

2 Answers2

6

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.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • thanks is worked for me but is give me Type safety: Unchecked cast from Serializable to ArrayList> this suppress warning so if i add Add@SuppressWarning is create any problem in future or older version – start android Jul 15 '13 at 05:46
  • its a lint warning about the cast. – Raghunandan Jul 15 '13 at 05:47
  • http://stackoverflow.com/questions/509076/how-do-i-address-unchecked-cast-warnings. here's one link that can help. its for type safety and its a lint warning. better to check the type cast. – Raghunandan Jul 15 '13 at 05:49
  • http://stackoverflow.com/questions/17089151/android-getchild-edittext-values-on-button-click-in-expandablelistview help me in this question – start android Jul 15 '13 at 13:22
  • why don't you ask a new question. i am sure the community can answer. i have not worked a lot on expandable listview. Any way i will look into it. – Raghunandan Jul 15 '13 at 13:24
1

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");
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71