Search code examples
androidxmlsqlitesaving-data

android save settings and information


i am new to android, i searched a lot and couldn't find a satisfying answer; what i need is to save some setting for my application such as

1> language, number of items to display, display/not display images, etc... which i think is best done using the shared preferences

2> save which data categories to get from the internet...

here is my problem:

i have data divided into category objects with key, name, type, data[]...(data[] is changing all the time and not saved after exiting the application),(key, name, type are final values defined by programmer).

and because there are many categories which the user may or may not want to load(around 25), he/she can choose which categories to display, and these choices must be saved.

i think using shared preferences will not help because of the complexity of the data; i was thinking of using sqlite or xml, not sure which is the best choice keeping in mind efficiency and memory size.

note: i am using a global variable for the category information array, that is because data[] needs to be refreshed automatically every 2-3 minutes and must be available to all activities also efficiency and memory space are an issue. i will appreciate any advice, thank you in advance.


Solution

  • 1> SharedPreferences is the right choice

    2> you have multiple possibilities

    a) Use the internal storage and use Object Serialization (for simplicity reasons), xml (if you want to exchange the data) or use a own format

    b) SQLite is the fastest solution. But you have to do more programming for that


    b would be my choice, so create a DB-Object (static or singleton pattern) and write functions for every database task