CONDEVX
CONDEVX

Reputation: 494

How clear Android Notification PendingIntent

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?

Upvotes: 1

Views: 2833

Answers (2)

Hantash Nadeem
Hantash Nadeem

Reputation: 488

->Just add PendingIntent.FLAG_UPDATE_CURRENT

Example:

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

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006819

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.

Upvotes: 1

Related Questions