0

I know that SQLite is technically designed for large amount of data when SharedPreferences are easier and faster for simple data types.

I want to store simple true false boolean for every day in a year. This means I either have to create 3 dimensional json and store it as string in shared preferences (or rather to dimensional array with year as key) or create table with year month and data as separate columns (or it could be simple date column... that being said I can also use "YYYY-MM-DD" as key in sharedPreferences for 365 booleans).

Now here's the question. Should I use more complex SQLite database for storing this simple data if I'm 100% sure I won't need any searching/grouping/selecting by special parameter capabilities. Because it seems to me that if I need to store simple boolean (even in case of 365+ booleans total) I should use SharedPreferences since it's a faster solution. But it just seems kind of wrong to me since I'm not sure whether SharedPreferences are supposed to store this much variables.

Add:

These booleans are stored locally only for offline load or rather faster access to from user perspective. These 1|0 values are stored on server for each app user so even if I would do some complex work with data, I'm not sure if I need to do it on a phone.

Vladimir
  • 388
  • 1
  • 13

2 Answers2

2

shared preferences can take 365 values .Max size of shared preferences is about 1.4mb according to this.How ever share prefs are generally used to save very small amount of data like volume or user settings. I would recommend you to go with sqlite database.It take some time to set it up but it would worth the time spent

Community
  • 1
  • 1
Manohar
  • 22,116
  • 9
  • 108
  • 144
  • 1
    Well that's something new. I didn't know it has some size restriction, you saved me from a lot of potential bugs haha. Thx – Vladimir Feb 19 '17 at 18:58
1

Storing your data in shared prefs may seem like a good idea, in fact it will just work fine, but it's taking an easy way. You never know what could you possibly need in the future. Your requirements are fulfilled at the moment, but it does not scale in any way. In general it's worth investing a little time and set up things properly and benefit in a long run.

Of course if you are doing some rapid prototyping or a quick demo it's a different story.

Setting a "complex db" or whatever does not have to be time consuming. Try Realm it's really fast.

Andrej Jurkin
  • 2,216
  • 10
  • 19
  • this realm thing sounds interesting, thank you for suggestion! Also, I dont think it would be wasted time even if I was going to build prototype. From my experience, these helpers are usefull across multiple projects and if programmed right way are very usefull and flexible and save more time in long run as you pointed out. – Vladimir Feb 19 '17 at 18:56