[android-developers] Widget-specific Preferences

2011-04-24 Thread Jake Colman

I am looking to implemented widget-specific preferences in my app.  I
have reviewed numerous blogs and posts, including Kostya's, and am
familiar with the overall approach of using the widget ID as a suffix to
the preference key.

I currently use a Preference Activity and a preference XML file to
manage my preferences.  Since a Preference Activity handles edits on its
own, is there still a way to use it if I need to change the key name at
runtime to have a widget id?  I am pretty sure I can get the widget from
the intent since it is launched as a configuration activity but can I
tap in and use it?

-- 
Jake Colman -- Android Tinkerer

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Widget-specific Preferences

2011-04-24 Thread Kostya Vasilyev

Jake,

It's possible to make your subclass of PreferenceActivity use a specific 
preference file by putting something like this inside its onCreate:


PreferenceManager prefManager = getPreferenceManager();
prefManager.setSharedPreferencesName("widget_pref_" + 
String.valueOf(widgetId));


This seems somewhat inefficient though, because each widget will get its 
own preference storage file.


To use a single preference file where each widget gets its own set of 
keys (dependent on a particular widget id), you could try using 
Preference.setKey:


for preference : all Preferences in the screen {
String keyOriginal = preference.getKey();
String keyWithWidgetId = keyOriginal + String.valueOf(widgetId);
preference.setKey(keyWithWidgetId);
}

Hope this helps.

-- Kostya

24.04.2011 17:28, Jake Colman пишет:

I currently use a Preference Activity and a preference XML file to
manage my preferences.  Since a Preference Activity handles edits on its
own, is there still a way to use it if I need to change the key name at
runtime to have a widget id?  I am pretty sure I can get the widget from
the intent since it is launched as a configuration activity but can I
tap in and use it?



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en