安卓:管理多个通知

编程入门 行业动态 更新时间:2024-10-19 22:34:12
本文介绍了安卓:管理多个通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的应用程序中创建多个通知。为了唯一标识每个通知,我已经给了他们一个独特的identificationId。以下是我的code:

I am trying to create multiple notifications in my application. To identify each notification uniquely, i have given them an unique identificationId. Following is my 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.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); }

问题: 当选择了通知,标签活动被称为传递意图。我想访问是在选项卡中选择通知的独特notificationId。我试过intent.putExtra()保存notificationId的意图。但是,对于多个通知其覆盖notificationId并返回最近的一次。我不明白,为什么发生这种情况,我怎样才能避免这种覆盖notificationId的。

Problem: When a notification is selected, Tabs activity is called passing the intent. I want to access the unique notificationId of the notification that was selected in Tabs. I tried intent.putExtra() to save the notificationId in the intent. But, for multiple notifications its overwriting the notificationId and returns the latest one. I dont understand as to why this is happening and how can i avoid this overwriting of notificationId.

谢谢, 钱德尔

推荐答案

我得到了答案。的意图都拿到缓存中,创建一个新的意图,只需添加下面这段code:

I got the answer. The intents were getting cached in. To, make a new intent, just add the following piece of code:

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

这使得意图是独一无二的。

This makes the intent unique.

此外,有人建议我下面这段code键使意图独特的:

Also, someone suggested me the following piece of code to make the intent unique:

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

它并没有帮助我,但可能会有所帮助别人。

It didnt help me, but might be of help to someone else.

- 钱德尔

更多推荐

安卓:管理多个通知

本文发布于:2023-11-27 08:04:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!