Reputation: 8702
I got a serious issue on my Android application
:
Calling
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
appWidgetManager.updateAppWidget(appWidgetId, getWidgetView(context, appWidgetId));
in the public void onReceive(Context context, Intent intent)
method has no result at all.
The RemoteViews
that are produced looks to be valid (programatically speaking) but the widget
is not updated (It keeps old values).
I've found some similar questions, but nobody has answer it:
Upvotes: 8
Views: 5356
Reputation: 91
Tried all updateAppWidget()
overloads, but it just doesn't work - whether called from onReceive()
or Activity
.
Strangely, notifyAppWidgetViewDataChanged()
does work in the same scenario.
EDIT:
Android/Launcher must be caching RemoteViews
, and if you call updateAppWidget()
with exactly same RemoteViews
- no rebind happens, despite what docs say, I can clearly see that my RemoteViewsFactory
is not called.
Because I needed to force UI rebind, ended up calling updateAppWidget()
with some dummy layout, and immediately after that with normal layout again:
try {
mgr.updateAppWidget(widgetId, new RemoteViews(context.getPackageName(), R.layout.dummy));
} finally {
mgr.updateAppWidget(widgetId, GetRemoteView(context, widgetId));
}
Upvotes: 5
Reputation: 1663
The solution posted by @Manitoba is not fully working, here is the working code to put inside onUpdate
:
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
// do your stuff
appWidgetManager.updateAppWidget(new ComponentName(context, CustomWidgetProvider.class), views);
Hope this will help :)
Upvotes: 9
Reputation: 196
What I've found for updating widget for xPeria is to add after .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
This line :
<intent>.setData(Uri.withAppendedPath(
Uri.parse("imgwidget://widget/id/"),
String.valueOf(allWidgetIds)));
Where is
Intent active = new Intent(context, <widget_provider>.class);
Upvotes: 2
Reputation: 8702
Solved:
The solution was quite weird but using
appWidgetManager.updateAppWidget(new ComponentName(context, CustomWidgetProvider.class), getWidgetView(context, appWidgetId));
solved my issue.
Upvotes: 6