我在我的 GCMIntentservice 中编写了一段代码,用于向多个用户发送推送通知。我使用 NotificationManager,在通知被点击时将调用 DescriptionActivity 类。我还将事件 ID 从 GCMIntentService 发送到 DescriptionActivity。
protected void onMessage(Context ctx, Intent intent) {
message = intent.getStringExtra("message");
String tempmsg=message;
if(message.contains("You"))
{
String temparray[]=tempmsg.split("=");
event_id=temparray[1];
}
nm= (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
intent = new Intent(this, DescriptionActivity.class);
Log.i("the event id in the service is",event_id+"");
intent.putExtra("event_id", event_id);
intent.putExtra("gcmevent",true);
PendingIntent pi = PendingIntent.getActivity(this,0, intent, 0);
String title="Event Notifier";
Notification n = new Notification(R.drawable.defaultimage,message,System.currentTimeMillis());
n.setLatestEventInfo(this, title, message, pi);
n.defaults= Notification.DEFAULT_ALL;
nm.notify(uniqueID,n);
sendGCMIntent(ctx, message);
}
在上面的方法中,我获取的事件ID是正确的,即我始终获得更新后的事件ID。但在下面的代码(DescriptionActivity.java)中:
intent = getIntent();
final Bundle b = intent.getExtras();
event_id = Integer.parseInt(b.getString("event_id"));
这里的event_id始终为"5"。无论我在GCMIntentService类中putExtra什么,我得到的event_id始终是5。有人能指出问题吗?是因为待处理意图吗?如果是,那我该如何处理?