Using PreferenceScreen / PreferenceActivity to Customize Home Screen Widgets

I am creating an appwidget where the user should be able to configure it before it is added to the main screen. For me, PreferenceScreen / PreferenceActivity seems ideal for the task, but the intent of these classes seems to customize the actual application. I searched but cannot find any documentation or tutorials that cover this issue.

Is it possible to customize the widget using these classes or is it the only alternative to customize it through the normal view?

Thanks for any answers!

+4
source share
2 answers

For this purpose, of course, you can use PreferenceActivity . If you configured it as an android:configure activity in customizing your widget, you will have to pretend a little to update your widget.

+14
source

CommonsWare: https://github.com/commonsguy/cw-advandroid/blob/master/AppWidget/LoremWidget/res/xml/widget_provider.xml your example does not use configuration activity at all and therefore not necessarily PreferencesActivity.

As for PreferencesActivities, it DOES NOT work for setResult (RESULT_CANCELED); in onCreate (9, and then setResult (...) in onBackPressed. There are wired NullPointerExceptions deep in Launcher.java (line 88X). However, it does work with Provider.updateAppWidget () and setResult (RESULT_OK, resultValue); in onCreate a then handle further updates in onBackPressed.

The following cut off may also help:

 onCreate() { CheckBoxPreference dark = (CheckBoxPreference)findPreference("xyz"); dark.setChecked(false); ... onBackPressed() { CheckBoxPreference dark = (CheckBoxPreference)findPreference("xyz"); boolean checked = dark.isChecked(); 

...

+1
source

Source: https://habr.com/ru/post/1309765/


All Articles