How to send HashMapString, Integer with another Activity

2

How can I send a Map<String,Integer>= new HashMap<>(); from one activity to another, using Intent ?

    
asked by Ramosaurio 10.08.2016 в 23:26
source

1 answer

1

It is similar to how it is done with another type of data:

Map<String,Integer> hashMap = new HashMap<String, Integer>();
Intent intent = new Intent(this, OtraActivity.class);
intent.putExtra("hashmap", hashMap);
startActivity(intent);

upon receipt of the Bundle in another Activity would be:

Intent intent = getIntent();
Map<String,Integer> hashMap = (Map<String, Integer>)intent.getSerializableExtra("hashmap");
    
answered by 10.08.2016 / 23:43
source