2010-08-06 82 views
6

我正在创建一个多站计时应用程序,其中将有多个计时器并行运行,并且每个通知都绑定到每个计时器。Android:在状态栏中管理多个通知

我可以使用下面的代码创建多个计时器。

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.setClassName("com.intuit.time_catcher.android.activities", 
    "com.intuit.time_catcher.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); 

} 

以下是im面临的问题。 考虑在状态栏中有3个计时器正在运行并且有3个通知。当我更新计时器2时,通知3(位于最右端)得到更新,但我真正想要做的是更新第二个通知(中间一个)。 当我打印通知ID的时候,即时看到正确的值。 我无法理解为什么我得到这种奇怪的行为?

回答

4

这听起来像你的意图会被缓存(这是出厂默认设置)

尝试加入了独特的setAction('anystring'+timestamp)或计数值,如本question

intent.setAction("actionstring" + System.currentTimeMillis()); 
+0

我试过了,但我仍然得到相同的问题 – 2010-08-06 22:39:04

+0

而不是intent.setAction()我用intent.setData()和它的工作 – 2010-08-12 17:36:44

1

应用程序解释它必须是唯一无法真正直接控制订单通知显示在...你是否看到它们被重新订购?

另外张贴三个通知是相当垃圾邮件。怎么样有一个,其内容显示所有3个计时器的状态?