Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android appwidget listview not updating

Tags:

I've written an AppWidget that displays some data in a ListView from a ContentProvider, but I have trouble having it update. When I first create the widget it gets populated correctly, but after the AlarmManager's PendingIntent arrives, no updates occurs on the ListView. Here's the code:

Intent update = new Intent(context, MenuWidgetProvider.class);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pIUpdate = PendingIntent.getBroadcast(context, 0, update, 0);
((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).
set(AlarmManager.RTC, nextTime.toMillis(false), pIUpdate);

Log.d(TAG, "updating: " + dmt.mealName);

for (int i = 0; i < appWidgetIds.length; ++i) {
    int widgetId = appWidgetIds[i];

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_menu);
    // meal name
    views.setTextViewText(R.id.widget_locname, prefs.getString(PREF_WIDGET_LOCNAME, ""));

    // adapter
    Intent adapter = new Intent(context, MenuWidgetAdapterService.class);
    adapter.putExtra(EXTRA_LOCATIONID, prefs.getInt(PREF_WIDGET_LOCID, -1));
    adapter.putExtra(EXTRA_MEALNAME, dmt.mealName);
    adapter.putExtra(EXTRA_DATE, dmt.date.toString());
    views.setRemoteAdapter(R.id.widget_list, adapter);

    // update
    manager.updateAppWidget(widgetId, views);
}

super.onUpdate(context, manager, appWidgetIds);

Weird thing is, when the update happens, the onUpdate() method runs--I see the output from the Log.d call--but there is no call to onDataSetChanged() in my RemoteViewsFactory. Even when I call notifyAppWidgetViewDataChanged, no effect.