2012-12-22 27 views
0

我有2個以報警管理器開始的通知。運行完美,但我有一個問題:當第一個通知處於活動狀態(在通知欄中)時,如果我沒有點擊它,並且第二個通知開始,我會看到新的通知,但是如果我單擊新的活動顯示第一個通知。勘誤通知活動

String ns = Context.NOTIFICATION_SERVICE; 
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); 

int icon = R.drawable.ic_launcher; 
CharSequence tickerText = not1[x]; 
long when = System.currentTimeMillis(); 

Notification notification = new Notification(icon, tickerText, when); 

CharSequence contentTitle = "title"; 
CharSequence contentText = not1[x]; 

Intent notificationIntent = new Intent("org.gortcloud.perledisaggezza", null, context, Notify.class); 
notificationIntent.putExtra("notify", not1[x]); 
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

notification.defaults |= Notification.DEFAULT_SOUND; 
notification.defaults |= Notification.DEFAULT_VIBRATE; 
notification.defaults |= Notification.FLAG_AUTO_CANCEL; 
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; 

final int HELLO_ID = 1; 

mNotificationManager.notify(HELLO_ID, notification); 
+0

有啥問題?你希望他們兩個都呆在那裏,直到你點擊它們或最新的一個才能正確行事? –

+0

我希望,當下一個通知開始時(並且我在通知欄上看到它時),我單擊通知並在活動(而不是前一個)中通知新通知。 –

回答

1

嘗試添加以下標誌到你的意圖之前,PendingIntent.FLAG_CANCEL_CURRENT

這樣的事情,

PendingIntent.getActivity(context,1, IntentObj, PendingIntent.FLAG_CANCEL_CURRENT); 

在你的代碼,

PendingIntent contentIntent = PendingIntent.getActivity(context, 1, notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT); 
+0

謝謝!完美運行! :-) –

+1

歡迎我的朋友.. –