Search code examples
androidandroid-appwidget

Android updateAppWidget doesn't update


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:


Solution

  • 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 :)