views:

88

answers:

1
+2  Q: 

Updating AppWidget

Hi, 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.

+1  A: 

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);
Josef
In which method of my class extending AppWidgetProvider should I add this?
Amit Chintawar
The snippet will update a `TextView` in your widget. You wrote that you want to update your widget when the user closes an `Activity` so that `Activity`'s `onPause` method would be a good place for example.
Josef