Reputation: 1685
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!
Upvotes: 0
Views: 1794
Reputation: 1598
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.
Upvotes: 2
Reputation: 3996
I suggest you send a broadcast message to the widget from the configuration activity. The same broadcast message that you will send otherwise to it when you want to refresh its state.
Intent refreshIntent = new Intent(this, WidgetProvider.class);
refreshIntent.setAction(WidgetProvider.ACTION_RELOAD);
refreshIntent.putExtra(WidgetProvider.EXTRA_WIDGET_ID, widgetId);
sendBroadcast(refreshIntent);
On the WidgetProvider you just process the new message received
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
// do your stuff here on ACTION_RELOAD
}
Upvotes: 0