Most of my Parcelable is working;
Simple things like out.writeString, out.writeInt, in.readString() etc are working perfectly.
My problem is when I want to Parcel an Array / List / ArrayList (I’ve tried them all).
I’m currently trying with:
Eclipse suggests that there is a
to read that data back in. But it’s not doing it for me.
What are we supposed to put into the ()?
I’ve tried nothing, with the result ‘Add argument to match…’
I’ve tried null, reference to the getter amongst others; which all return the error ‘cannot convert from void to List’
‘cannot convert from void to List’
From that error it sounds like you’re trying to assign the return type of the method
readStringList(...) to a
List<T> variable. In other words: are you perhaps writing something like:
List<String> stringList = in.readStringList(stringList)
readStringList(...) returns a void, so that might be what Eclipse is complaining about. You actually should not be trying to a get a return type from a void method – in this case you need to supply the variable to which the result should be assigned as a parameter. Hence, this should suffice:
List<String> stringList = null; in.readStringList(stringList)
By the way, if you’re implementing Parcelable in order to be able to pass relatively simple data objects between activities (using Intents), consider using the Serializable interface in stead – it’ll save you tons of work, especially if you need to repeat the same process for multiple objects.
Write to parcel:
Read from parcel
List<String> newList = in.createStringArrayList();