I wrote an AppWidget that displays some data in a ListView from a ContentProvider, but I have problems updating it. When I first create a widget, it fills correctly, but after receiving the AlarmManager PendingIntent request in the ListView, no updates occur. Here is 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);
It's strange when the update happens, the onUpdate () method starts - I see the output from the Log.d call, but in my RemoteViewsFactory there is no call to onDataSetChanged (). Even when I call notifyAppWidgetViewDataChanged, there is no effect.
buntwoi
source share