我想在我的应用程序中创建多个通知。为了唯一标识每个通知,我已经给了他们一个独特的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.
- 钱德尔
更多推荐
安卓:管理多个通知
发布评论