4

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.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Amit Chintawar
  • 20,450
  • 1
  • 17
  • 17

2 Answers2

4

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 Pfleger
  • 74,165
  • 16
  • 97
  • 99
0

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);
rdmc
  • 21
  • 5