2010-08-12 40 views
9

Uygulamamda birden çok bildirim oluşturmaya çalışıyorum. Her bildirimi benzersiz bir şekilde tanımlamak için onlara benzersiz bir kimlik verdim. Aşağıdaki benim kodudur:Android: Birden çok bildirimi yönetme

private void updateNotification(int notificationId, int clockStatusID, CharSequence text) { 
//notificationManager.cancel(notificationId); 
// throws up an ongoing notification that the timer is running 
Log.i("TIMERCOUNT", "Notification id: " + notificationId); 
Notification not = new Notification(clockStatusID, // the 
    // icon 
    // for 
    // the 
    // status 
    // bar 
    text, // the text to display in the ticker 
    System.currentTimeMillis() // the timestamp for the 
    // notification to appear 
); 
Intent intent = new Intent(); 
intent.putExtra("notificationID", notificationId); 
intent.setAction("actionstring" + System.currentTimeMillis()); 
intent.setClassName("com.chander.time.android.activities", 
"com.chander.time.android.activities.Tabs"); 


not.setLatestEventInfo(self, 
    getText(R.string.timer_notification_title), 
    getText(R.string.timer_on_notification_text), PendingIntent 
    .getActivity(this, 0, intent, 
     PendingIntent.FLAG_UPDATE_CURRENT)); 

not.flags += Notification.FLAG_ONGOING_EVENT; 
not.flags += Notification.FLAG_NO_CLEAR; 
notificationManager.notify(notificationId, not); 
} 

Sorun: Bir bildirim seçildiğinde, Sekmeler aktivite niyet geçirerek denir. Sekmelerde seçilen bildirimin benzersiz bildirimine erişmek istiyorum. Ben niyetinde notificationId kaydetmek için intent.putExtra() çalıştı. Ancak, birden fazla bildirim için notificationId'nin üzerine yazarak en yenisini döndürür. Bunun neden olduğunu anlayamıyorum ve bu bildirimin üzerine yazılmasını nasıl engelleyebilirim.

sayesinde Chander

cevap

15

yanıtını aldım. Intents'in önbelleğe alma edildi sadece aşağıdaki kod parçasını ekleyin yeni niyeti yapmak için:. Bu niyet benzersiz kılan

saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); 

.

Ayrıca, birisi niyet benzersiz yapmak için bana aşağıdaki kod parçasını önerdi:

saveCallIntent.setAction("actionstring" + System.currentTimeMillis()); 

Bana yardım etmedi, ama başkasına yardım olabilir.

7

--Chander sadece pendingIntent içinde notificationId yerine 0 koyun.

PendingIntent.getActivity(this, notificationId, intent,PendingIntent.FLAG_UPDATE_CURRENT)); 

Kullanıcı ayrıca, çalışmakta olan kodu almak için yukarıdaki koduyla birlikte aşağıdaki kodu da güncelleştirmelidir.

mNotificationManager.notify(notificationId, mBuilder.build()); 
İlgili konular