Rangtian Yu Rangtian Yu - 1 year ago 92
Android Question

How to put List<HashMap> into Bundle?

In my Fragment, there is a

List<HashMap> movieList

How could I store movieList into Bundle in

public void onSaveInstanceState(Bundle outState) {


Thank you.

Answer Source

You can try this way...

HashMap<String, String> contactsMap = new HashMap<>();
contactsMap.put("key1" , "value1");
contactsMap.put("key2" , "value2");

ArrayList<HashMap> list = new ArrayList<>();

Bundle b = new Bundle();
b.putSerializable("HASHMAP", list);

ArrayList<HashMap> hashmapList = (ArrayList<HashMap>)            b.getSerializable("HASHMAP");
HashMap<String, String> map = hashmapList.get(0);

for (Map.Entry<String, String> entry : map.entrySet()) {
    System.out.println(entry.getKey()+" : "+entry.getValue());

You will get the same data. Make sure your movie model class is serializable.