WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue.
cordova -v):7.0.1cordova platform ls): android 6.2.3this.localNotifications.on("click", function(notification){
console.log("sup");
});
the "sup" should appear only one time.
the "sup" appear more than one time
_Reproduce this issue; include code to reproduce, if relevant_
setReminder(){
let options = {
id: this.info.id,
title: this.info.title,
text: this.info.message,
at: new Date(this.info.enddate),
sound: 'file://audio/song.wav',
};
this.localNotifications.schedule(options);
}
constructor(){
this.localNotifications.on("click", function(notification){
console.log("sup");
});
}
i will first schedule the notification.
After the notification appear, when the user click on the notification it will update the database when the user click on the notification.
_Include iOS / Android logs_
How are you triggering the event? Thats what the "Steps to Reproduce" is for.
sorry for missed out, i have updated the steps to reproduce.
So is the notification in the background, the foreground, is the app stopped or started?
it is on "background", and the app did start, works like normal. the things is tat it trigger the console.log multiple times instead of one.
I'll check it again with Android 7.0 but with Ionic 1. My recollection was that we never got ANY "click" event to work. We don't use Ionic 2 so can't comment on that.
I have the same problem, did you find a work around yet?
Please try out with 0.9-beta
If the callback gets called multiple times, its often that the code adds the callback within a callback, which was executed twice.
I was facing the same issue. However, I later realized the mistake I was making:
I had the registration code for "click" event in the same function as that for handling a new notification. This way, every time a new notification came, the event registration also increased by 1 and would lead to multiple firings of the event:
receiveNotificationMessage(message) {
console.log("Notification Received: " + message);
let notificationData = JSON.parse(message);
this.localNotifications.schedule({
id: notificationData.Id,
title: "Notification Recieved",
text: "Notification Body",
led: 'FF0000',
autoClear: true,
smallIcon: 'res://notification.png',
data: notificationData
});
let onclickObservable = this.localNotifications.on("click");
onclickObservable.subscribe((notification) => { console.log(notification); });
I solved this by moving the "click" registration to the constructor.
Try to confirm that your constructor is not being fired multiple times.
Most helpful comment
I was facing the same issue. However, I later realized the mistake I was making:
I had the registration code for "click" event in the same function as that for handling a new notification. This way, every time a new notification came, the event registration also increased by 1 and would lead to multiple firings of the event:
receiveNotificationMessage(message) { console.log("Notification Received: " + message); let notificationData = JSON.parse(message); this.localNotifications.schedule({ id: notificationData.Id, title: "Notification Recieved", text: "Notification Body", led: 'FF0000', autoClear: true, smallIcon: 'res://notification.png', data: notificationData }); let onclickObservable = this.localNotifications.on("click"); onclickObservable.subscribe((notification) => { console.log(notification); });I solved this by moving the "click" registration to the constructor.
Try to confirm that your constructor is not being fired multiple times.