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?
From the menu bar, click File > Settings (on macOS, click Android Studio > Preferences).
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() .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With