0

Since the Parcel doc says that

changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

So I wonder is there a way to monitor the process, so that we can prevent placing Parcel data to persistent storage.

Also, does the Serializable object has the same problem, if it does, how to monitor.

twlkyao
  • 14,302
  • 7
  • 27
  • 44

1 Answers1

1

So I wonder is there a way to monitor the process, so that we can prevent placing Parcel data to persistent storage.

A Parcel is never written to persistent storage. That is part of the point of having Parcelable in addition to Serializable.

does the Serializable object has the same problem

Changes in a Serializable class may cause problems when you try to read in older values.

how to monitor

Since you are the one writing your Serializable objects to disk, monitor it yourself. There is no place that I can think of where Android will automatically write a Serializable class of yours to disk.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I have test Serializable, it crashes when you change the member type, other condition, it works fine, such as change the member name, remove or add a member. – twlkyao Oct 24 '17 at 10:49
  • I have encountered intentional write parcel to persistent storage, such as Parcel parcel = Parcel.obtain(); object.writeToParcel(parcel, 0); contentValues.put("key", parcel.marshall()); – twlkyao Oct 24 '17 at 10:55
  • @twlkyao: Whoever wrote the code in your latter question is violating the `Parcel` contract. If this is in the AOSP somewhere, file an issue. If this is in an app that you control, fix it. – CommonsWare Oct 24 '17 at 11:21
  • Yes, this is in our app, I can find the call by search Parcel.obtain(), marshall or unmarshall, I will add some method try to prevent other people do this. – twlkyao Oct 24 '17 at 11:45