是的,dave.c 给出的链接在很大程度上是正确的,但是如果使用由集合支持的小部件,在我的例子中是一个数据库,稍微修改一下就可以得到预期的结果:
private void updateAllWidgets() {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext().getApplicationContext());
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(getContext().getApplicationContext(), ListWidgetProvider.class));
if (appWidgetIds.length > 0) {
// Tell the widgets that the list items should be invalidated and refreshed!
// Will call onDatasetChanged in ListWidgetService, doing a new requery
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.notes_list);
}
}