question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

on ('click) ran for multiple times

See original GitHub issue

WARNING: 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
ashwin-kamblicommented, Apr 19, 2018

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:

       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.

0reactions
katzercommented, Oct 30, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery click events firing multiple times - Stack Overflow
Save this answer. Show activity on this post. an Event will fire multiple time when it is registered multiple times (even if to...
Read more >
Using the Collection Runner | Postman Learning Center
Select one or more collection runs and select Delete to remove them. The start time of the collection run. The run source, duration, ......
Read more >
Clickthrough rate (CTR): Definition - Google Ads Help
CTR is the number of clicks that your ad receives divided by the number of times your ad is shown: clicks ÷ impressions...
Read more >
MSTest runs tests multiple times when run from Solution ...
This happens when I right-click on a test class in Solution Explorer, and then select “Run Tests”. It does not happen in Test...
Read more >
Issue with button runs onselect multiple times on single click
Hi, I am facing strange issue in powerapps saving data using button control. I am not sure if anyone has faced similar issue....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found