我有多个小部件。在每次更新时,我都会在服务中启动一个服务代码:
for (int widgetId : allWidgetIds) {
// Register an onClickListener for DisplayActivity
Intent clickIntentUpdate1 = new Intent(
this.getApplicationContext(), DisplayActivity.class);
clickIntentUpdate1.putExtra("widgetid", widgetId);
clickIntentUpdate1.putExtra(DisplayActivity.WHAT, what);
clickIntentUpdate1.putExtra(DisplayActivity.WHAT_COLOR, prefs
.getString(QuoteConfigure.PREF_PREFIX_KEY_QUOTE_COLOR
+ widgetId, "Transparent"));
clickIntentUpdate1.putExtra(DisplayActivity.WHO, who);
clickIntentUpdate1.putExtra(DisplayActivity.WHO_COLOR, prefs
.getString(
QuoteConfigure.PREF_PREFIX_KEY_QUOTE_BY_COLOR
+ widgetId, "Transparent"));
clickIntentUpdate1.putExtra(
DisplayActivity.BG_COLOR,
prefs.getString(QuoteConfigure.PREF_PREFIX_KEY_QUOTE_BG
+ widgetId, "Transparent"));
PendingIntent pendingIntentUpdate1 = PendingIntent.getActivity(
getApplicationContext(), 0, clickIntentUpdate1,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.what,
pendingIntentUpdate1);
Log.d("quoteSERVICE", what + " -> " + who);
Log.d("quoteSERVICE", "what inside intent:"+clickIntentUpdate1.getExtras().getString(DisplayActivity.WHAT));
Log.d("quoteSERVICE", "widgetid:"+widgetId);
Log.d("quoteSERVICE", "--------------------");
// Register an onClickListener for Who search
Intent clickIntentSearch = new Intent(Intent.ACTION_VIEW);
clickIntentSearch.setData(Uri
.parse("http://www.google.com/search?q=" + who));
PendingIntent pendingIntentSearch = PendingIntent.getActivity(
getApplicationContext(), 0, clickIntentSearch, 0);
remoteViews.setOnClickPendingIntent(R.id.who,
pendingIntentSearch);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
stopSelf();
现在的问题是:
我有两个小部件,当它们更新 R.id.who 上的意图时,它应该与所需的数据一起被触发。然而,R.id.what 的事件并没有按预期触发。在此事件上发送的数据是发送内容和发送者的最后一个值(即最后一个要更新的小部件中的值。)