0

I need to send an object ModuleDetection from an activity to another. I've found that using the Parcel class to turn my object into a Parcelable object would help me. However, in every example I could find, the parcelable object's attributes had default types of Android. But the ModuleDetection object has an attribute of ImageInterface type, another class that I made.

When writing the method :

@Override
public void writeToParcel(Parcel dest, int flags) {
}

I can't use methods like dest.writeInt() or dest.writeString() , because my attribute hasn't a default type of android. How can I do this?

Matthias
  • 4,481
  • 12
  • 45
  • 84
  • Implement Parcelable in both ModuleDetection & ImageInterface. Then you can pass its objects. – Vikram Mar 18 '16 at 10:53
  • make the other class `Parcelable` as well and use `dest.writeParcelable(Parcelable p, int parcelableFlags)` to write it – pskink Mar 18 '16 at 10:55

2 Answers2

1

You should make both classes implement Parcelable. When you pass your ModuleDetection object as a parcelable, the ImageInterface field will get handled as well.

manabreak
  • 5,415
  • 7
  • 39
  • 96
1

You should make both classes implement Parcelable. When you pass your ModuleDetection object as a parcelable, the ImageInterface field will get handled as well.

You can make your ImageInterface extend Parcelable so each ImageInterface implementation will have to implement also parcel

Here is an example