I'm trying to use Parceler to transfer variable of ArrayList>, but it always give error when running, just link intent.putParcelableArrayListExtra("votedetail", arrlist);. Searched and found no example, how to use it? Thank you in advance.
-
Please provide more details about the error you get. Probably it has to do with the object types you have in the `ArrayList`. The `ArrayList` can't be parceled if the objects it contains are not Parcelables. As far as I know, Android SDK implementations of `Map
` do not implement `Parcelable`. – B0Andrew Oct 25 '17 at 14:54
3 Answers
Please take a look at the method's signature on Android Developer docs:
Intent putParcelableArrayListExtra (String name, ArrayList<? extends Parcelable> value)
The objects in the ArrayList
have to be Parcelable
s.
As far as I know, Android SDK implementations of Map<K,V>
(HashMap
, SortedMap
, etc) do not implement Parcelable
. You will have to write your own implementation which will also be Parcelable
.

- 1,725
- 13
- 19
B0Andrew, Thank you for your help. I found the answer at last. Using putParcelableArrayList to do it. First wrap the
"Arraylist<Map<String, String>>"
to become Arraylist(new one Arraylist, then add the variable), then I can use putParcelableArrayList to transfer the data.

- 7
- 2
Parceler is a library for serializing Parcelable
objects. There is no need to use putParcelableArrayListExtra()
, just use putParcelable()
:
List<Map<String, String>> value = new ArrayList<>();
// Fill out List
intent.putParcelable("votedetail", Parcels.wrap(value));
And you may deserialize in the onCreate
of the receiving activity:
List<Map<String, String>> value = intent.getParcelableExtra("votedetail");
You can find examples on how to use it directly on the website: http://parceler.org/

- 10,995
- 4
- 45
- 75