Android Widget Shows Strange Image During Update
Solution 1:
I had the exact same issue in my widget as you described and searched a lot for a solution and couldn't find any. What I ended up doing is some kind of workaround that seems to work fine in my case. What i did is the following, instead of updating the widgets directly from the onUpdate() method, I started a service that handled the update then killed itself. This solved it on the emulator and on a device that had the widget stuck during update. Here's a sample code:
The AppWidgetProvider:
@Override
publicvoidonUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){
context.startService(newIntent(context, WidgetService.class));
}
The Service:
@OverridepublicvoidonStart(Intent intent, int startId) {
started(intent);
}
@OverridepublicintonStartCommand(Intent intent, int flags, int startId) {
started(intent);
return START_STICKY;
}
privatevoidstarted(Intent intent) {
//update here the widgetsContextcontext= getApplicationContext();
updateWidgets(context);
stopSelf();//killing the service
}
privatevoidupdateWidgets(Context context) {
AppWidgetManagerappmanager= AppWidgetManager.getInstance(context);
ComponentNamecmpName=newComponentName(context, widgetClass);
int[] widgetIds = appmanager.getAppWidgetIds(cmpName);
RemoteViewsrView=newRemoteViews(context.getPackageName(), layoutId);
for (int wid : widgetIds) {
//all updates here
rView.setTextViewText(tvId, desc);
appmanager.updateAppWidget(wid, rView);
}
}
Note sure why this workaround solves the issue, but the good thing is that it does Hope this helps
Solution 2:
I had this issue on 4.0 & 4.2 when manually sending android.appwidget.action.APPWIDGET_UPDATE
broadcast to update the widget.
Fixed by using a custom action, e.g.
<intent-filter><actionandroid:name="android.appwidget.action.APPWIDGET_UPDATE" /><actionandroid:name="android.appwidget.action.APPWIDGET_DISABLED" /><actionandroid:name="my.app.action.APPWIDGET_REFRESH" /></intent-filter>
Post a Comment for "Android Widget Shows Strange Image During Update"