0

I usually use the interface Parcelable to pass data from one Activity to another. It is working fine if the data isn't that much. However, there are cases where I have to pass a lot of data to an Activity. Marshalling of these data seems to happen without any error but unmarshalling results in an Error like this:

07-23 14:26:34.215: E/AndroidRuntime(29379): java.lang.OutOfMemoryError: java.lang.Object[] of length 1075971147 exceeds the VM limit

It seems that it is just too much data to get unmarshalled. A really Hackish solution (that I really don't like) will be to give that special Activity a static Method to pass that data to it, looking for it at onCreate(). This would work at least for Activitys I have control over the source, but fails if I haven't.

I wanna know if there are other acceptable attemts, to pass a bunch of data from one Activity to another. It would be really nice if I could reuse some code I already wrote for the Parcelable interface, but that is not an requirement

Rafael T
  • 15,401
  • 15
  • 83
  • 144
  • There may be alternate solutions to passing that much data around, depending on what kind of data it is. Can you elaborate on what sort of things you're trying to pass between activities? – Jon O Jul 23 '12 at 13:10
  • I have to pass buisness-model-objects. These usually contain rawTypes, or other parcelable-buisness-model objects which contains again, just raw-types (Strings, ints, floats, booleans). – Rafael T Jul 23 '12 at 13:19

2 Answers2

1

How about creating a global variable (like described here)? There was a time I was struggling with the same problem and in the end it was all I found working (even though I cannot say "global" appears like a "good practice").

Community
  • 1
  • 1
alex
  • 10,900
  • 15
  • 70
  • 100
  • I think that is exactly the point: `global` in any kind of occurence (let it be a Singleton, or static members) is bad design from my point of View. Assume over 50 Actvitys and only 1 needs that `global` information. I don't like the idea of storing it `globally` just in case Activity XX will need access to it. – Rafael T Jul 23 '12 at 13:07
  • I know what you mean and cannot agree more. But Activities are very separate entities and I haven't yet seen any other way to send data across them other than using `Serializable`, `Parcelable` or global variable. – alex Jul 23 '12 at 13:11
1

How about using a Bus architecture (EventBus/Otto), then you can transfer any POJO between any Android components.

aprofromindia
  • 1,111
  • 1
  • 13
  • 27