iam开发一个android应用程序,其中iam获取多个gcm通知当应用程序处于打开状态但所有应用程序关闭时,所有通知都以不同的数据打开但我只能获取多个通知一个打开,当我点击其他通知时,它不会重新启动具有不同数据的活动。只有一个gcm通知在Android应用程序关闭时打开
String title = intent.getExtras().getString("title");
String message = intent.getExtras().getString("info");
String lat = intent.getExtras().getString("lat");
String lng = intent.getExtras().getString("lng");
Intent notificationIntent = null;
if(title.equals("blockage"))
{
notificationIntent = new Intent(context, ViewBlockage.class);
}
else if(title.equals("icrequest"))
{
notificationIntent = new Intent(context, IntercarAlert.class);
message=intent.getExtras().getString("reqMessage"); // change the message here for request message
notificationIntent.putExtra("reqName", intent.getExtras().getString("userName"));
}
else if(title.equals("icresponse"))
{
notificationIntent = new Intent(context, InterCarResponseAlert.class);
}
notificationIntent.putExtra("title", title);
notificationIntent.putExtra("message", message);
notificationIntent.putExtra("lat", lat);
notificationIntent.putExtra("lng", lng);
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String appName = context.getString(R.string.app_name);
// set intent so it does not start a new activity
//notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent =PendingIntent.getActivity(context, gcmCounter, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
// update current must for every time get updated pending intent otherwise it will provide wrong intent values
notification.setLatestEventInfo(context, appName, message, pIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(gcmCounter, notification);
gcmCounter++;
你可以发布你的活动代码吗? – 2014-11-01 04:44:55