Hybrid Developer
Hybrid Developer

Reputation: 2340

How to send a List<HashMap<String,String>> list to another activity

I was trying to send List> list to another activity. I tried many ways but couldn't. Please help!

Upvotes: 0

Views: 442

Answers (1)

Oli
Oli

Reputation: 3536

You could use Intent

hashMap.put("key", "value");
Intent intent = new Intent(this, otherActivity.class);
intent.putExtra("mapkey", hashMap);
startActivity(intent);

EDIT:

For fatching the value in otherActivity

    Intent intent = getIntent();
    HashMap<String, String> hashMap = (HashMap<String, String>) intent.getSerializableExtra("mapkey"); 
    intent.getSerializableExtra("mapkey");

EDIT (Convert it back to List) try sth like:

HashMap<String, String> map = new HashMap<String, String>();
List<String> hashMap = new ArrayList<String>(map.values());

Happy coding!

Upvotes: 1

Related Questions