Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use PreferenceActivity to configure widget, how retrieve preference?

Tags:

android

widget

i'm using PreferenceActivity class to configure my widget. PreferenceActivity class automatically saves user preferences, so in widget update service i can call context.getSharedPreferences() and i obtain user preferences. Problem is follow: if you have many widget of same type, how PreferenceActivity class saves prefs? how i can load appWidgetId specific prefs from sharedPreferences?

like image 850
Premier Avatar asked Jul 04 '10 18:07

Premier


People also ask

How do I access preferences in Android Studio?

From the menu bar, click File > Settings (on macOS, click Android Studio > Preferences).

How do I use preference fragments?

Use PreferenceFragmentCompat to programatically handle preferences. To load the settings into the fragment, load the preferences in the onCreatePreferences() method. To get an instance of a preference, search for a preference using its key through the PreferenceManager within onCreateView() .

What is preference activity Android?

PreferencesActivity is a way to easily create preference screens such as those in Android itself, just look under Settings . These can be used inside applications to easily save preferences to SharedPreferences and then easily access these from within your app. See this page for more information on PreferenceActivity.


1 Answers

For AppWidgets and preferences I really liked this tutorial

http://www.helloandroid.com/tutorials/mastering-android-widget-development-part1
http://www.helloandroid.com/tutorials/mastering-android-widget-development-part2
http://www.helloandroid.com/tutorials/mastering-android-widget-development-part3

They give a tutorial where a preference is saved for jointly with the appwidget ID and it is shown how it is retrieved for updating the individual widgets.

like image 61
thomasd Avatar answered Sep 29 '22 13:09

thomasd