Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

click is always triggered for the last notification #14

Open
hewerlin opened this issue Oct 6, 2017 · 0 comments
Open

click is always triggered for the last notification #14

hewerlin opened this issue Oct 6, 2017 · 0 comments

Comments

@hewerlin
Copy link

hewerlin commented Oct 6, 2017

Expected Behaviour

With multiple notification, the onclick method of the notification that is clicked should be invoked.

Actual Behaviour

Whatever notification is clicked, the onclick method of the LAST notification is invoked.

Reproduce Scenario (including but not limited to)

Steps to Reproduce

  • Show 2 notifications with distinct tags and click events
  • Click Notification 1
  • Note that the click event for notification 2 is invoked

Platform and Version (e.g. Android 5.0 or iOS 9.2.1)

Android

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Samsung

Cordova CLI version and cordova platform version

cordova --version                                    # e.g. 6.0.0
6.4.0

cordova platform version android                     # e.g. 4.1.1
6.0.0

Plugin version

cordova plugin version | grep phonegap-plugin-local-notification   # e.g. 1.5.3
1.0.1

Sample Code that illustrates the problem

  var n1 = new Notification("Notification 1", { tag: "N1", body: "" });
  n1.onclick = function() { alert("CLICKED: 1"); };

  var n2 = new Notification("Notification 2", { tag: "N2", body: "" });
  n2.onclick = function() { alert("CLICKED: 2"); };

Logs taken while reproducing problem

Found Reason

In LocalNotifications.java there is a single static field
private static CallbackContext notificationContext;
That field is assigned every time a notification is displayed.
LocalNotifications.fireClickEvent(String tag) always refers to that static field no matter which notification was clicked, so the last notification gets the click event. Also, the tag parameter of that method is ignored.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

1 participant