I need to pass one ArrayList
by one Intent
to another Activity
and according to what I have read on the Internet, I need the objects of the to ArrayList
be Parcelable
, but I have no idea how to do this.
Can someone explain to me how to pass a ArrayList
by a Intent
?
I have tried using putExtra
and putParcelableArrayListExtra
, but still the same. This is my Intent
output:
ArrayList<String> data = selectData(position);
Intent intent = new Intent(this, ItemActivity.class);
intent.putParcelableArrayListExtra("datos", data);
startActivity(intent);
It is also necessary to say that I cannot use anything other than a ArrayList
because the number of data that I am going to pass will never have the same name and will always be X data.
If there was another way, it would also serve as an answer.
Thanks in advance.
There are two ways to send an ArrayList through an Intent :
Via putExtra(String name, Serializable value)
This is how it is received in SecondActivity.java :
It is also done using the putStringArrayListExtra (String name, ArrayList value) method , where you implicitly define that the data type to send is an ArrayList:
This is how it is received in SecondActivity.java :
Try passing it through
putExtra
like this:yourOtherActivity: