Martin's Tex-Blog

Posts on programming and generally technical topics

Posts Tagged ‘android

Moving to PreferenceActivity

leave a comment »

PreferenceActivity seems to be the best choice when it comes to allowing user edit application settings. If you started with custom dialog with lots of widgets for your preferences and now you want to move to PreferenceActivity then be prepared for some difficulties:

– your Shared Preferences keys must be of String type and values must be of String or Boolean types.
– if you have any int values in your preferences, then remember to convert it to string before PreferenceActivity will touch it, otherwise be prepared for exceptions
– you should not start PreferenceActivity derived Activity class using sub-activities, but rather use SharedPreferences.OnSharedPreferenceChangeListener and apply changes once preference changes, this might cause troubles if processing is time consuming
– if you used arrays.xml for your widget allowed values (ie. spinner), then make sure that allowed values are strings, ie.if you had 3 then change it to “3”. PreferenceActivity works with Strings – remember.
– and remember to read docs on PreferenceActivity, since its methods are heavily deprecated since HONEYCOMB release


Written by Marcin

December 26, 2011 at 1:59 am

Posted in Uncategorized

Tagged with