I was trying to send List> list to another activity. I tried many ways but couldn't. Please help!
5
-
Try sending it as an arrayNiko– Niko2013-05-16 11:13:37 +00:00Commented May 16, 2013 at 11:13
-
I tried it but couldn't make it.Hybrid Developer– Hybrid Developer2013-05-16 11:14:08 +00:00Commented May 16, 2013 at 11:14
-
if your list is an arraylist, it is serializablenjzk2– njzk22013-05-16 11:21:18 +00:00Commented May 16, 2013 at 11:21
-
sorry its not an arraylistHybrid Developer– Hybrid Developer2013-05-16 11:23:35 +00:00Commented May 16, 2013 at 11:23
-
What does your data represent?MaciejGórski– MaciejGórski2013-05-16 11:37:21 +00:00Commented May 16, 2013 at 11:37
Add a comment
|
1 Answer
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!
7 Comments
Hybrid Developer
How will you receive this in the second activity?
Hybrid Developer
but now we have a hashmap, how to convert it as a list?
Hybrid Developer
List<HashMap<String,String>> list
Hybrid Developer
its not working. for your info its giving an error "The method putExtra(String, boolean) in the type Intent is not applicable for the arguments (String, List<HashMap<String,String>>)"
Oli
could you please try,
List<HashMap<String>> hashMap = (List<HashMap<String>) else you could try with string,boolean.. ill test it |