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