我有一个带有配置活动的小部件,它更新小部件上的文本视图。它工作正常,但需要在刷新按钮上更新相同的文本视图,该按钮调用相同的配置活动。这次配置活动不会更新文本视图,因为它具有无效的小部件 ID。
我通过 Widget ID
Intent 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();
}
请帮忙。