My app widget functions in a number of modes. For each of these modes, I created a RemoteViewsFactory
. To switch between modes, I send an intent to my AppWidgetProvider
. Upon receiving it, I create the RemoteViews
and pass it to AppWidgetManager
's updateAppWidget()
. To set a RemoteViewsFactory
for a collection view, I call RemoteViews
' setRemoteAdapter()
:
rv.setRemoteAdapter(appWidgetId, R.id.widget_view_flipper, intent);
R.id.widget_view_flipper
is the collection view, intent
is for RemoteViewsService
to construct the appropriate factory.
EDIT: I edited the question because I figured out the originally described problem. Now it's that when I change factories, getViewAt()
of the new factory is called after the change, but the element in the collection view simply doesn't update! How would that happen?
For now the only thing I've come up with is that I can call AppWidgetManager's notifyAppWidgetViewDataChanged with a delay after the factory replacement, it causes the element in the view to update with an ugly blinking.
After half a day of digging, I came up with a workaround.
When I need to update a widget and replace a factory, do the following in AppWidgetProvider:
appWidgetManager.updateAppWidget(appWidgetIds[i], null);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
where rv is the new RemoteViews.
The old RemoteViews is cached in AppWidgetHostView, this way we can get rid of the cached data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With