Search code examples
androidandroid-activityrefreshandroid-appwidget

Android - AppWidgetProvider refresh content after configure activity


I've got a configuration activity fired from an appWidget button. If some parameters for the app are changed within the configuration activity, once saved those i should close the current activity (finish()) and refresh the appWidjet textviews content. Any chance I can force the refresh/update? Thanks!


Solution

  • You can update appswidget from any activity on any event in app:

     RemoteViews views = new RemoteViews(getPackageName(), R.layout.appswidget);
     views.setTextViewText(R.id.txtInfo, "Tiwari");
     ComponentName thisWidget = new ComponentName(v.getContext(), WidgetProvider.class);
     AppWidgetManager manager = AppWidgetManager.getInstance(InfoActivity.this);
     manager.updateAppWidget(thisWidget, views);
    

    here RemoteViews view that will updated here, and by manager.updateAppWidget(), onUpdate() of AppWidgetProvider will called and refresh on appWidget.

    you will get here a good demo.