Monday, July 12, 2010

Android SharedPreference Read-Once Gotcha

I use SharedPreferences in a horrible way.  I use it to store application data. It's much easier to use a key/value store than a SQLite DB or writing to a file.  

Because SharedPreferences are stored in the /data/data directory they can't be reached without root for saving.  To fix this I store a copy of the file on the /sdcard.  On start up I copy the "public" version over the /data/data private file.  (This has the side effect of allowing modification of the data and reloading by editing the file when attached to a computer)

The problem is that when you call getSharedPreferences you always get the same instance back. It doesn't reload the file.  This was an issue for me because I was using that to create the /data/data file if it didn't exist, copy the /sdcard file over and then tried to reload by calling it again.  

To fix the problem I had to check if the /data/data file existed during the copy operation and create through java.io.File methods first, then copy, then call getSharedPreferences.

Sunday, July 11, 2010

Drop And Give Me Twenty! v2.0

Just pushed version 2.0 to the market!  Added a lot of user requested features:

  • Reset
  • Manually change your level and day/week
  • Manual entry (It's more of a stopwatch mode)
  • Sound on/off
  • Minor updates to the Progress chart to make it more flexable
I don't know which is more nerve wracking, the update because I can destroy data now or the initial release due to the unknown.

Tuesday, June 15, 2010

First Android app published!

Last night I finished up version 1.0 of my 100 pushup app for Android and published it to the market. You can search for DGMT to install.
I hope to add a few more things to finish up. I want to add a proximity counter for those who don't want to touch the screen with their nose.  An editor for the exercises. Better graphing through custom coding instead of using a library. And in the far future uploading data to a web app for generating custom workouts for your skill level based on others like you.
(Use Barcode Scanner on this QR code for a direct link to my app in the market.)