-1

I have a List in one of my activity. I need to pass it to another activity and use the elements in it.

ActivityOne.java

newsListy.add(new News(title, description, thumbnail);
      Intent newsIntent = new Intent(getActivity(),Second.class);
                    newsIntent.putExtra("NewsItems", newsListy);
startActivity(newsIntent);

Second.class

data =  in.getSerializableExtra("NewsItems");

Also, retrive value from the list and assign it to a String title, description and thumbnail

user3534519
  • 89
  • 1
  • 2
  • 10
  • Its been answered a dozen times. [This][1] one, for example [1]: http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android – A Nice Guy Apr 25 '14 at 10:04
  • @Arnab. I know how to pass single data. I wanted to know about passing a List – user3534519 Apr 25 '14 at 10:35

2 Answers2

1

If you want to pass a custom object between activities, like for instance a List of a custom object :

List<'CustomObject'>

Your custom object class have to implement Parcelable.

Alex DG
  • 1,859
  • 2
  • 22
  • 34
0

Be sure that your Object implements Serializable interface or else you will get some kind of parse exception. But as @Alex mentioned also declare your List's generic type with your Object like : List<'CustomObject'>

Implementing Parcelable is the best way to do it, but it requires more effort.

Ercan
  • 3,705
  • 1
  • 22
  • 37