Skip to content

click is always triggered for the last notification #14

Open
@hewerlin

Description

@hewerlin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions