I am creating an Android application (in Java) and am trying to save objects between lifecycles and make certain that they are saved, even after onDestroy() might be called. From my research there appears to be 3 ways to save objects long-term.
1) Serialization 2) Parcelable 3) JSON (specifically via Gson)
Furthermore, I must pass these objects between activities. I know that Parcelable is not really meant for saving objects, and Serialization is very slow in Android, and may not be geared towards passing via Intents. I am not that familiar with Gson as of yet.
I want a means of saving objects which is also forgiving (that is, I can edit the structure of the objects between release updates and not render previous Objects useless, or am able to restore said objects to the newer version).
Is JSON (specifically via Gson) the best way for me to go about persisting my Objects through lifecycles as well as passing my objects via intents?
Thank you!
Maybe not necessarily Json data, but perhaps XML, or even just raw text data that can be stored on the SD Card, or Internal storage if an SD Card isn't present would work. As long as the user doesn't remove your data, there shouldn't be any issues with storing data that way.
From there, even if you did decide to change something about how you store your data, you could write a converter that detects deprecated data and would upgrade it.
Also on a side note, you may want to use the intent to pass a message to the other activity to do something with the stored data instead of passing a bunch of data through the intent pipeline.
A message could be something as simple as a string, or perhaps even an integer, that can be interpreted by the receiving activity in order to complete a set of actions.