我有一个带有Configuration活动的Widget,它可以更新widget上的Text视图。它工作正常,但需要在刷新按钮上更新相同的文本视图,刷新按钮调用相同的配置活动。此时配置活动不会更新文本视图,因为它具有无效的窗口小部件ID。
我通过
传递了Widget IDIntent refreshIntent = new Intent(context, WidgetActivity.class);
refreshIntent.setAction(ACTION_WIDGET_REFRESH);
PendingIntent refreshPendingIntent = PendingIntent.getActivity(context, 0, refreshIntent, 0);
remoteViews.setOnClickPendingIntent(R.id.button3, refreshPendingIntent);
refreshIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetIds[0]);
在接收方
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
请帮忙。