0

How i can send and receive ArrayList with intent? For example:

ArrayList<model> m=new ArrayList<model>();

the ArrayList contains string boolean and...

i tried this:

intent.putParcelableArrayListExtra(DATA,(ArrayList<? extends Parcelable>) m)

amir dt
  • 83
  • 2
  • 9

3 Answers3

1

put arraylist in Bundle Like :

ArrayList<String> images=new ArrayList<>();    
Bundle bundle = new Bundle();
bundle.putSerializable("images", (Serializable) images);

and then put into intent extra.

Abhay Koradiya
  • 2,068
  • 2
  • 15
  • 40
1

Assuming an ArrayList<Model>:

For using putParcelableArrayListEtra() you need your Model class to implement the Parcelable interface. This involves quite a lot of boilerplate code, however, there is a plugin for Android Studio you can use to generate that code automatically.

Another option is, to make the Model class implement Serializable and use putSerializable().

Ridcully
  • 23,362
  • 7
  • 71
  • 86
1

To send any object via Intent object should implements Serializable or Parcelable. Your model class should implement Serializable or Parcelable.

To send ArrayList via Intent all objects inside ArrayList should implements Serializable or Parcelable Check Parcelable and Serialization tutorial.

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50