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

99封情书 提交于 2019-11-30 11:49:42

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!