on ('click) ran for multiple times
See original GitHub issueWARNING: IF YOU IGNORE THIS TEMPLATE, WE’LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Provide a general summary of the issue.
Your Environment
- Plugin version:3.12.1
- Platform: android
- OS version:
- Device manufacturer / model: redmi note 3
- Cordova version (
cordova -v
):7.0.1 - Cordova platform version (
cordova platform ls
): android 6.2.3 - Plugin config
- Ionic Version (if using Ionic) 3.4.0
Expected Behavior
this.localNotifications.on("click", function(notification){ console.log("sup"); });
the “sup” should appear only one time.
Actual Behavior
the “sup” appear more than one time
Steps to Reproduce
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"); });
}
Context
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.
Debug logs
Include iOS / Android logs
- ios XCode logs
- Android: $ adb logcat
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top GitHub Comments
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:
I solved this by moving the “click” registration to the constructor. Try to confirm that your constructor is not being fired multiple times.
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.