Using PreferenceScreen/PreferenceActivity to configure home screen widgets

后端 未结 2 1544
渐次进展
渐次进展 2021-02-10 14:34

I\'m creating an appwidget, where the user should be able to configure it before it is added to the home screen. To me, PreferenceScreen/PreferenceActivity seems perfect for the

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-10 15:27

    commonsWare: https://github.com/commonsguy/cw-advandroid/blob/master/AppWidget/LoremWidget/res/xml/widget_provider.xml your example does not use a config-activity at all and thus certainly no PreferencesActivity.

    As far as PreferencesActivities go, it does NOT work to 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 do Provider.updateAppWidget() and setResult(RESULT_OK, resultValue); in onCreate and then handle further updates in onBackPressed.

    The following snipped may help too:

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

    ...

提交回复
热议问题