由网友(一生醉笑)分享简介:我试图通过PendingIntent发送额外的数据。Hi I'm tried to send extra data via PendingIntent.这是我的code //**1**Intent intent = new Intent(context, UpdateService.class); intent....
我试图通过PendingIntent发送额外的数据。
Hi I'm tried to send extra data via PendingIntent.
这是我的code
//**1**
Intent intent = new Intent(context, UpdateService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
intent.putExtra(BaseConfigurationActivity.EXTRA_WIDGET_MODE,
2);
// put appWidgetId here or intent will replace an intent of
another widget
PendingIntent pendingIntent =
PendingIntent.getService(context, appWidgetId, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.gridview_button,
pendingIntent);
//**2**
intent = new Intent(context, UpdateService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetId);
intent.putExtra(BaseConfigurationActivity.EXTRA_WIDGET_MODE,
1);
// put appWidgetId here or intent will replace an intent of
another widget
pendingIntent = PendingIntent.getService(context, appWidgetId,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.listview_button,
pendingIntent);
在我的code将其分配pendingIntent两个按钮gridview_button与EXTRA_WIDGET_MODE 2 和listview_button与EXTRA_WIDGET_MODE 1
In my code it assign pendingIntent to two button gridview_button with EXTRA_WIDGET_MODE 2 and listview_button with EXTRA_WIDGET_MODE 1
当我点击gridview_button并调用UpdateService类 我也得到了EXTRA_WIDGET_MODE值为1
when I click on gridview_button and it call UpdateService class I also got EXTRA_WIDGET_MODE value is "1"
我在做什么错了?
推荐答案
最后,我发现了问题,这种情况发生,因为我发送相同的请求code
Finally I found problem this happen because I send the same "requestCode"
PendingIntent.getService(context, appWidgetId
这应该是这样的。
It should be like this
PendingIntent.getService(context, 0
PendingIntent.getService(context, 1
相关推荐
最新文章