1

I'm trying to send an arrayList of ParseObjects from one activity to another with the following code:

Intent intent = new Intent(MainActivity2.this, Activity2.class);
intent.putExtra("arrayList", list);
startActivity(intent);

where list is the arrayList of ParseObjects obtained from a parse query denoted by ArrayList. Some of the ParseObjects are unParcebale as they contain ParseFile and Location data.

I keep getting the error:

java.lang.RuntimeException: Parcel: unable to marshal value com.parse.ParseObject@b308c828

How do I get rid of this error and successfully send and then obtain the ArrayList in the second Activity? Thanks

  • One of the `parseObject` members must not be `Parcelable`. – nstCactus Aug 12 '14 at 12:42
  • @nstCactus indeed. It contains a parseFILE. What should I do? – Ire Adewolu Aug 12 '14 at 12:44
  • @IreAdewolu I posted what you should do in the answer below. Personally, I would recommend using JSON or GSON. There's also a "hackish" solution which I deliberately didn't mention in my answer: Using a public static class to simply store the list in one activity and retrieve it in the other. Sadly, it's also the easiest solution. – 0101100101 Aug 12 '14 at 13:28

2 Answers2

3

ParseObject is either not Serializable nor Parcelable. You have to use a custom wrapper to send the data you want and rebuild your ParseObject on the new Activity.

pdegand59
  • 12,776
  • 8
  • 51
  • 58
1

There's no way you can pass something to other Activities (nor Fragments) that is not one of the types shown here. Most importantly, objects you want to pass have to be either Serializable or Parcelable. Try Jamie Chapman's ParseProxyObject, which wraps ParseObject in a Serializable, found here. But please check the documentation of Serializable first:

Implement Serializable Judiciously

Refer to Effective Java's chapter on serialization for thorough coverage of the serialization API. The book explains how to use this interface without harming your application's maintainability.

Recommended Alternatives

JSON is concise, human-readable and efficient. Android includes both a streaming API and a tree API to read and write JSON. Use a binding library like GSON to read and write Java objects directly.

Community
  • 1
  • 1
0101100101
  • 5,786
  • 6
  • 31
  • 55