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
?
Asked
Active
Viewed 134 times
0

Rafael T
- 15,401
- 15
- 83
- 144
2 Answers
1
I guess <= Integer.MAX_VALUE
/**
* Returns the total amount of data contained in the parcel.
*/
public final native int dataSize();

nyjsl
- 311
- 1
- 3
-
what is your expected Result of `dataSize()` if one Parcels the String "Foo"? How to calculate the amount being added before adding it? – Rafael T Jul 09 '12 at 11:39
-
1int length ="Foo".getBytes().length; – nyjsl Jul 11 '12 at 05:44
0
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.

karllindmark
- 6,031
- 1
- 26
- 41
-
Could not be the problem! The mechanism does work on most phones, but fails on some (usually HTC devices) – Rafael T Jul 09 '12 at 10:05
-
-
yes. The error occurs if I try to save Activity state in `onSavedInstanceState` and insert my Parcelable inside this Bundle. It occurs if I try to pass that Parcelable between Activitys, too. While Samsung Nexus S will unparcel that without any Exception, an HTC Desire does not – Rafael T Jul 09 '12 at 11:36
-
Could you provide us with the code in question, and also the answer to the following question: What versions of Android are your devices running? – karllindmark Jul 09 '12 at 12:08
-
I think that the discussion about code doesn't belong here. First, it doesn't fit the question HOW MANY DATA one is able to store, second I'm shure I have a correct implementation (It works on most devices). Device Versions are from 2.1 to 2.3.7 – Rafael T Jul 09 '12 at 12:33