本文介绍了通过PendingIntent问题发送额外的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过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 2and listview_button with EXTRA_WIDGET_MODE 1
当我点击gridview_button并调用UpdateService类我也得到了EXTRA_WIDGET_MODE值为1
when I click on gridview_button and it call UpdateService classI 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
这篇关于通过PendingIntent问题发送额外的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!