我正在尝试在我的应用程序中创建多个通知.为了唯一地识别每个通知,我给了它们唯一的identifierId.以下是我的代码:
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,intent,PendingIntent.FLAG_UPDATE_CURRENT)); not.flags += Notification.FLAG_ONGOING_EVENT; not.flags += Notification.FLAG_NO_CLEAR; notificationManager.notify(notificationId,not); }
问题:
当选择通知时,Tabs活动称为传递意图.我想访问在Tabs中选择的通知的唯一notificationId.我试图intent.putExtra()来保存notifyId的意图.但是,对于多个通知,它覆盖了notificationId并返回最新的通知.我不明白为什么会发生这种情况,我如何避免这种覆盖notificationId.
谢谢,
钱德尔
解决方法
我得到了答案.意图正在缓存.为了做一个新的意图,只需添加以下代码:
saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
这使得意图是独一无二的.
另外,有人建议我使用以下代码来使意图独一无二:
saveCallIntent.setAction("actionstring" + System.currentTimeMillis());
它没有帮助我,但可能对别人有帮助.
–Chander
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。