I have been using the Serializable interface to pass an object from one activity to another. I am using putExtra on the sender side and getSerializable on the receiver side. Everything works fine but I have received (for the first time) the following error report:
java.lang.RuntimeException: Parcelable encountered IOException reading
a Serializable object
I don’t understand why this exception has been generated since I am using getSerializable and not getParcelable.
I know that I should implement the Parcelable interface instead because it has been designed specifically for Android (and that’s what I will end up doing) but I want to understand why I am getting this error.
Thanks!
Parcelableis mentioned in this error because anIntentyou send from oneActivityto another has aBundleinside and thisBundleisParcelable. When you callIntent.putExtra()this extra is added to the innerBundle. WhenIntentis passed between activities itsBundleis converted to and from a byte array and so is yourSerializableobject.But I don’t know why this error occurs. Maybe it’s because of some bug in
writeObject()/readObject()implementation.