2

Lets say that you have two classes ObjA and ObjB. ObjB is derived from ObjA.

If your implementing parcelable in ObjB, do you also need to parcel ObjA also??

I have a project that when I tried the above it would not work but once I combined ObjA and ObjB together the application worked.

I saw a question which linked to this site but the derived class had ObjA inside ObjB. I am simply extending ObjA so do I still need to parcelable both classes???

barakisbrown
  • 1,293
  • 3
  • 9
  • 15

2 Answers2

0

if i understand you correctly, objB extends objA. In that case I think you are looking to put parcelable in objA so that objB gets it too.

if your plan is to make a special class that implements parcelable and have many other classes extend that class it is tricky because members and fields in objB need to be written in the same order in which they were read, so objA needs to sort properly and it needs to know what types the members of objB are so that it can read and write the proper types. Luckily i wrote a class that does just this:

https://github.com/awadalaa/Android-Global-Parcelable

Alaa Awad
  • 3,612
  • 6
  • 25
  • 35
0

According to my understanding,

If ObjB is a ObjA - No need for implementing parcelable in ObjA if this is done in ObjB.

But,

If ObjB has a ObjA - You need to implement parcelable in ObjA only if you send it's state via the parcel.

R.daneel.olivaw
  • 2,681
  • 21
  • 31