[英]Android: Managing multiple notifications in status bar
I am creating a multiple stop watch application for which there will be multiple timers running parallel, and each notification binded to each timer. 我正在创建一个多停止监视应用程序,其中将有多个并行运行的计时器,并且每个通知都绑定到每个计时器。
I am able to create multiple timers with the following code. 我可以使用以下代码创建多个计时器。
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);
}
The following is the problem that im facing. 以下是我面临的问题。 Consider there are 3 timer running and 3 notifications in the status bar.
考虑状态栏中有3个计时器运行和3个通知。 When i update timer 2, notification 3(which is at the rightmost end) gets updated, but what i really want to do is to update the second notification(middle one).
当我更新计时器2时,通知3(位于最右端)得到更新,但我真正想做的是更新第二个通知(中间一个)。 When i print the notification id's, im seeing the right values.
当我打印通知ID时,我看到了正确的值。 I cant comprehend why am i getting this weird behavior?
我无法理解为什么我会得到这种奇怪的行为?
It sounds like your intents are cached (which is the factory default) 听起来你的意图被缓存(这是出厂默认值)
Try adding a unique setAction('anystring'+timestamp)
or a count value, it must be unique as explained in this question 尝试添加一个唯一的
setAction('anystring'+timestamp)
或计数值,它必须是唯一的,如此问题中所述
intent.setAction("actionstring" + System.currentTimeMillis());
An application can't really directly control the order notifications are shown in... are you just seeing them re-ordered on you? 一个应用程序无法真正直接控制订单通知显示在......你刚看到它们重新订购了吗?
Also posting three notifications is pretty spammy. 发布三个通知也很垃圾。 What about having one, whose content shows the state of all 3 timers?
如果有一个,其内容显示所有3个计时器的状态?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.