Android SharedPreferences Performance

While playing with a widget and remote views, I was noticing a perceptible lag in GUI update time when I was toggling a setting.  I thought the lag might have been due to the nature of the remote view architecture, as it has to pass some info across processes.  The lag itself was about 50ms, which is just noticeable when you are waiting on a "toggling" view to change.  It turned out that this delay was due to updating a single boolean in shared preferences.  This can take even longer on some devices.

For the moment, I just modified things so that the GUI was updated before updating shared preferences.   If this were more time-critical, or if there were enough shared preferences being updated to cause even poorer performance, I would consider wrapping the update process in an AsyncTask.

Popular Posts