How clear Android Notification PendingIntent

痴心易碎 提交于 2020-01-24 01:30:11

问题


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.

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;
}
}

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?

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


回答1:


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

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

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

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




回答2:


->Just add PendingIntent.FLAG_UPDATE_CURRENT

Example:

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);



来源:https://stackoverflow.com/questions/9878620/how-clear-android-notification-pendingintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!