多くのユーザーにプッシュ通知を送信するコードを GCMIntentservice に記述しました。通知がクリックされたときに DescriptionActivity クラスを呼び出す NotificationManager を使用します。また、event_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);
}
ここで、上記の方法で取得している event_id は正しいです。つまり、常に更新されたものを取得します。ただし、以下のコード (DescriptionActivity.java) では:
intent = getIntent();
final Bundle b = intent.getExtras();
event_id = Integer.parseInt(b.getString("event_id"));
ここでの event_id は常に「5」です。GCMIntentService クラスに何を入れても、取得する event_id は常に 5 です。誰か問題を指摘してもらえますか? 保留中の意図が原因ですか? はいの場合、どのように処理すればよいですか?