4

我正在从 AppWidget 的 buttonclick 上启动一个活动。用户在活动中输入一些数据,当用户关闭活动时,我想更新用户在 AppWidget 上的 TextView 中输入的数据。知道怎么做吗?我已经从 AppWidget 成功启动了活动,唯一的问题是更新 AppWidget。

4

2 回答 2

4

您可以使用RemoteViewsAppWidgetManager

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);
于 2010-07-30T15:46:21.400 回答
0

您可以从宿主应用程序活动或片段中调用 appwidget 更新方法。

这就是我的做法:

    int[] ids = AppWidgetManager.getInstance(getApplication()).
    getAppWidgetIds(new ComponentName(getApplication(), MyWidget.class));
    MyWidget myWidget = new MyWidget();
    myWidget.onUpdate(this, AppWidgetManager.getInstance(this),ids);
于 2018-07-16T17:44:39.143 回答