我正在创建一个多停止监视应用程序,其中将有多个并行运行的计时器,并且每个通知都绑定到每个计时器.
我可以使用以下代码创建多个计时器.
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);
}
Run Code Online (Sandbox Code Playgroud)
以下是我面临的问题.考虑状态栏中有3个计时器运行和3个通知.当我更新计时器2时,通知3(位于最右端)得到更新,但我真正想做的是更新第二个通知(中间一个).当我打印通知ID时,我看到了正确的值.我无法理解为什么我会得到这种奇怪的行为?
听起来你的意图已被缓存(这是出厂默认值)
尝试添加唯一值setAction('anystring'+timestamp)或计数值,它必须是唯一的,如本问题中所述
intent.setAction("actionstring" + System.currentTimeMillis());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1558 次 |
| 最近记录: |