Reputation: 20688
I'm launching an activity on a buttonclick from AppWidget. The user enters some data on the activity and when user closes the activity, I want to update the data user entered in a TextView on AppWidget. Any idea how to do that? I have successfully launched activity from AppWidget, only problem being updating the AppWidget.
Upvotes: 4
Views: 1024
Reputation: 21
You can call the appwidget update method from the host application activity or fragment.
This is how I have done it:
int[] ids = AppWidgetManager.getInstance(getApplication()).
getAppWidgetIds(new ComponentName(getApplication(), MyWidget.class));
MyWidget myWidget = new MyWidget();
myWidget.onUpdate(this, AppWidgetManager.getInstance(this),ids);
Upvotes: 0
Reputation: 74507
You can use RemoteViews
and the AppWidgetManager
:
AppWidgetManager manager = AppWidgetManager.getInstance(context);
RemoteViews remoteViews = new RemoteViews(
context.getPackageName(), R.layout.widget);
remoteViews.setTextViewText(R.id.textBoxId, "new textbox content");
manager.updateAppWidget(appWidgetId, remoteViews);
Upvotes: 4