user2799407
user2799407

Reputation: 559

Android - How to pass HashMap<String,List<String>> between activities?

I want to pass HashMap object through intent. My Hashmap is contains String and List. HashMap> listDataChild; I want to pass listDataChild to next activity?

Upvotes: 0

Views: 586

Answers (2)

Larry Schiefer
Larry Schiefer

Reputation: 15775

Attach it to the Intent as part of a Bundle. HashMap is Serializable so it will work in a Bundle or even as a Extra to the intent.

Upvotes: 0

Pratik Dasa
Pratik Dasa

Reputation: 7439

Try below code:

Intent intent=new Intent(CURRENT CLASS.this, CLASS TO CALL.class);
                    intent.putExtra("test", YOUR HASHMAP);
                    startActivity(intent);

In another Activity get data like below:

HashMap<String, List<String>> data=(HashMap<String, List<String>>) this.getIntent().getSerializableExtra("test");

Upvotes: 1

Related Questions