Thursday, March 13, 2014

Android - Type Safe SharedPreferences

OK, so how many time did you get so pissed because of the way you had to use the SharedPreferences and store stuff on Android?

I know this drove me mad more than once, and the fact I have to copy paste some implementation from one app to another was even more frustrating...

So.......  I've thought a while back to make a generic storage utility object, specifically for Android, (I already have something like that for Pure Java) and after a long while I have. I know this is a bit overkill, but hell, I would gladly pay with few extra lines of code to save hundreds, for a readable, comfortable and quick coding.

If you find the code useful, leave me a comment... I would like to know I'm not doing this for no good reason!

For me the code is pretty obvious, but then again I've been at it for years... let me know what is not clear so I can elaborate more about these subjects.



-- UPDATE --

I've released Cyborg not too long ago, and this sort of generic shared preferences is build in and optimized further in terms of how much code you need to write, You can find it here.

6 comments:

  1. nice work!!. but I looks complex for a beginner. checkout this wrapper I made that addresses the issue... https://github.com/kcochibili/TinyDB--Android-Shared-Preferences-Turbo

    ReplyDelete
    Replies
    1. Thanks KC, This code was not meant for real beginners, though the example should be simple enough to use even for a beginner.
      As for your implementation... that was my initial approach which is good and is enough but I love generics, and that is why with the years it turned into this one...

      Delete
  2. Replies
    1. Sorry, I've missed that when rearranging my repositories.

      Delete
  3. Oops, you've found a dead link.
    please live the link...

    ReplyDelete
    Replies
    1. Sorry, I've missed that when rearranging my repositories.

      Delete