0

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 array Commented May 16, 2013 at 11:13
  • I tried it but couldn't make it. Commented May 16, 2013 at 11:14
  • if your list is an arraylist, it is serializable Commented May 16, 2013 at 11:21
  • sorry its not an arraylist Commented May 16, 2013 at 11:23
  • What does your data represent? Commented May 16, 2013 at 11:37

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

7 Comments

How will you receive this in the second activity?
but now we have a hashmap, how to convert it as a list?
List<HashMap<String,String>> list
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>>)"
could you please try, List<HashMap<String>> hashMap = (List<HashMap<String>) else you could try with string,boolean.. ill test it
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.