In my Android application I have several activities where the user configures a certain operation. In every step of the configuration I store the parameters supplied by the user in a Static Class that manages this operation. After the configuration all activities can access these parameters and everything works perfect.
Except that I want to persist this configuration so in future executions of the app there is no need to configure it again.
How can I restore the static class state?
I didn’t want to create a table in the database just to store this one object (I think it is an ugly solution).
I could also dump all the configurations into a SharedPreferences, however I have a lot of parameters in the manager, and it stores lists of objects with the results of the operation execution, and it would be a bit pain in the ass to manually store it in a Key/Value solution.
Instead I was thinking on serializing the class into a file, and on the application startup I check if the file exists, if true, I deserialize it into my Manager again.
Is this a correct approach, or are there prettier solutions? Also, would the lists objects in this static class be serialized, or do I need to serialize each of them separately?
I was thinking on doing something like shown in this example
I think serializing to a file is an excellent idea. Seems a lot cleaner and simpler than dealing with databases or key/value pairs. Otherwise it feels like you are serializing the serialization.
And to answer your second question: Generally, implementations of java.util.List will implement java.io.Serializable, so you do not need to do them separately.
I would do exactly what you describe with the file, and in that example.