Android Widget: Show configuration activity before widget is added to the screen

前端 未结 2 1844
北恋
北恋 2021-01-02 02:32

I have an Android Widget that uses web services to retrieve and display the data on the widget. The widget has a configuration activity that extends PreferenceActivity

相关标签:
2条回答
  • 2021-01-02 02:49

    From android documentation: http://developer.android.com/guide/topics/appwidgets/index.html#Configuring

    The onUpdate() method will not be called when the App Widget is created (the system will not send the ACTION_APPWIDGET_UPDATE broadcast when a configuration Activity is launched). It is the responsibility of the configuration Activity to request an update from the AppWidgetManager when the App Widget is first created. However, onUpdate() will be called for subsequent updates—it is only skipped the first time.

    HOWEVER, this does not seem to be correct!

    What I did was adding a boolean to SharedPreferences which tells me if this widgetId has been through configuration. If not skip this update. Implement this in your AppWidgetProvider class' onUpdate method.

    0 讨论(0)
  • 2021-01-02 02:57

    Declare ActivityConfig in manifest:

    <activity android:name="com.zoostudio.moneylover.widget.ActivityWidgetConfig" android:label="Hello Widget Config"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> </intent-filter> </activity>

    With update widget class:

    public abstract class SampleWiget extends AppWidgetProvider {
    

    }

    follow android developer widget support to understand it.

    0 讨论(0)
提交回复
热议问题