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