0

Iam working on an android application and have trouble making a decision for the architecture saving application data. Following case:

In the app the user has the possibility to create new general objects and give them properties he want. To support this, i want to give them a list with favorites before creating the input form, for example a car. It has color, weight, speed, horsepower etc. So the user can choose a often picked object (for example the car) and will get the appropriate fields for the form he has to fill (color, weigth ...). This list should be smart. The more you pick an item, the higher it appears in the list. And this presets have to be editable in preferences.

And thats the point. Should I implement my idea with the preferences framework from android (save it to xml as different preferences types and simply load due preferencebuilder) or should i create own xml objects and save it to self created user file location?

My second question: if i use the preference framework method .... is this made good for dynamically add entries at runtime? the ressources are in the res folder, but what if there are individual user entries? will they also be saved in the program folder or is there a special user data folder where the files (maybe encrypted) are in?

Thank you

harrow
  • 178
  • 1
  • 11

1 Answers1

0

Storing such complex data in SharedPreferences is tricky. What I mean is assuming user created 4 objects and each has 8 properties. You would store 4*8 values in sharedprefs and map them too.

What can be done is maintain an array list of objects created by user. Consecutive to that list maintain counter array list and keep swapping both lists internally as per number of times user has clicked the object. example:

List Name                List Counter
ObjA                        5
ObjB                        3
ObjC                        1
ObjD                        1

Store these two lists in Shared Prefs.

Now, for the object's properties part (2 possibility arises) :

Maintain a mySQL DB and a table for each object's name. You can store values of each column in it IF you need to store every instance created of the object by user. (every time user clicks the object just show him/her the column names of table and store the values entered)

Example :

ObjA Table :

Color   speed   horsepower   rpm
________________________________
red      20mph    100        3000
black    80mph    500        8000

Consecutively, if you don't want to store every instance value, you can make another sharedPrefs with object as key and an Arraylist of properties as value.

Karan
  • 2,120
  • 15
  • 27
  • Okay, the idea, giving the most picked object a score and sort by it is good. But i dont thought about using a SQL DB for saving data. For flexible data i personally think, an xml document is better because i dont have to add columns or new tables to my db. Only add a node to the xml tree and save this back on close. – harrow May 01 '15 at 20:48
  • I haven't worked on storing data to xml directly (indirectly via SharedPrefs). If it suits your model then awesome! – Karan May 01 '15 at 20:49
  • Thank you. Its also nice to know, that this is not a trivial challenge. If often tend to do it more complicated than it is. – harrow May 01 '15 at 21:02
  • sure! let me know how it plays out – Karan May 01 '15 at 21:04