Search code examples
androidandroid-activitystateparcelable

How to gracefully handle Parcelable implementation changes when storing to disk after all?


I'm currently writing a View library that gets rid of the need for Activities and Fragments and should be more easy to understand and so on and so forth. Anyway that's my goal.

However I struggle to come up with a solution on how to store state. I get the state from child Views as Parcelable, however according to the Android docs, the Parcelable implemetation may break some day

As such, it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

Since this seems to be the only possible solution and it is only for state (the same way an Activity uses it), it should be fine.

The question I ask myself now is, how does an Android Acitivty handle up or downgrades internally? (Do they even store states when the device is rebooted?) Would there be any way to know when the implementation changes so I don't destroy all apps using my lib?

(Should I just ignore the issue because historically it never broke?)


Solution

  • Persistent storage means saving to disk, i.e., surviving beyond the lifecycle of your process.

    Android only stores Parcelable data (such as that tied to an Activity) while the process is alive, meaning it never runs into these issues. As long as you are doing something similar, then there is no issue.