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)

0

3 Answers 3

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().

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

1 Comment

Thanks for your help.
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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.