Android Notification PendingIntent的清晰度如何 [英] How clear Android Notification PendingIntent

查看:75
本文介绍了Android Notification PendingIntent的清晰度如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建警报的活动.警报会呼叫广播接收器.在接收时,我用活动中的其他内容(ID,标题,内容)创建一个通知.警报触发广播接收器很好地创建了通知.

I got a Activity which creates an alarm. The alarm calls a Broadcast Receiver. In on Receive i create a Notification with the extras from the Activity (ID, Title, Content). The Alarm triggers the Broadcast Receiver creates the notification well.

但是,当我重新安装应用程序或安装新版本并设置带有新标题和内容的新警报时,接收方会向我显示第一个创建通知意图.我可以创建可能会触发警报的所有作品,但它们始终显示第一个创建通知的意图.

But when i re install the application or install a newer version and setup a new Alarm with a new title and content the receiver shows me the first create notification intent. i can create may Alarm triggers all works but they show always the first create Notification intents.

我使用内部应用程序计数器创建通知ID

I use a internal application counter for creating a notification ID

public class CollectApplication extends Application {

private Integer reminderCount;

@Override
public void onCreate() {
reminderCount = 1;
super.onCreate();
}

public Integer getReminderCount() {
return reminderCount;
}

public void setReminderCount(Integer reminderCount) {
this.reminderCount = reminderCount;
}
}

当然,在重新安装或更新应用程序之后,计数器将从1开始.但是我创建了一个具有相同ID 1的新意图,所以我可以正确覆盖它吗?

Of course after re installing or updating the application the counter starts from 1. But i create a new intent with the same ID 1 so i override it right?

如何覆盖它或从通知中删除意图以创建具有新功能的新显示?

How to override it or remove the intent from the notification to create a new one with new extras to display?

还是我应该将当前ID保存在共享首选项中?

Or Should i save the current ID in the shared preferences?

推荐答案

如何覆盖它或从通知中删除意图以创建具有新功能的新显示?

How to override it or remove the intent from the notification to create a new one with new extras to display?

为新的 Notification 创建 PendingIntent 时,请使用 FLAG_UPDATE_CURRENT .

Use FLAG_UPDATE_CURRENT when you create your PendingIntent for the new Notification.

还是我应该将当前ID保存在共享首选项中?

Or Should i save the current ID in the shared preferences?

否,因为您应该只有一个ID.不过,您可能希望保留提醒次数.

No, because you should only have one ID. You may wish to persist your reminder count, though.

这篇关于Android Notification PendingIntent的清晰度如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆