How many data a Parcel can store?
-
19-06-2021 - |
Question
I encountered a problem using Parcelables
to share Informations between Activitys. I have no Problem with the implementation, but with its behavior on some phones. It seems, that the information stored inside is just too much. This leads to MemoryExceptions thrown when that objects are getting unmarshalled. I couldn't find any kind of a memory-limit inside the docs. What is the best way to find out, if given Informations are small enaugh to write/read them into/from a Parcel
, before the Parcelable
is written to a Parcel
?
Solution
I guess <= Integer.MAX_VALUE
/**
* Returns the total amount of data contained in the parcel.
*/
public final native int dataSize();
OTHER TIPS
What type of data are you storing in your Parcels? I've noticed that if you mess up (ie don't ensure that you store and retrieve the data the same way), you'll end up getting really weird results, some even causing your application to throw an OutOfMemoryException.
TLDR; Make sure you read & write to a Parcel in the same order.