I'm trying to figure out the best way to persist data for my Android application. The situation at the moment is there are objects created in one activity (UserItem) and objects created in another activity (SuggestionItem). I'm still thinking about structure at the moment but those will probably be subclasses of the same parent class (Item) with some common attributes like name and location.
SuggestionItem currently has a composition relationship with an object that holds most of its data. That object has type Suggestion, which has a few subclasses like RestaurantSuggestion and HotelSuggestion.
What I want to do is to have a third activity that displays a view of all the SuggestionItems and UserItems that are created. I was thinking of storing them in an SQLite database, as they should be saved between application closes/restarts. In the future there may also be some sort of exporting/importing, but I am ok with only thinking about saving these objects for now and redesigning the database later.
My question is, should I create a schema with tables for my classes and columns that match their fields, or should I instead serialize these objects? They're fairly simple; perhaps around 10 primitive and String fields per class (things like url, pricePerNight, imageUrl). The only non-primitive field there is is a LatLng field, which could just be turned into a couple of double fields for latitude and longitide. I know about two serialization methods with Android: gson and implementing Serializable. I'm not sure which would be more appropriate.
Can anyone with more experience give me advice? Sorry for the wall of text.
Aucun commentaire:
Enregistrer un commentaire