Skip to content

Commit

Permalink
Add conditional check to only add notification click listener once
Browse files Browse the repository at this point in the history
- Introduced a boolean flag to track whether the notification click listener has already been added
- Updated `addNotificationClickListener` method to only add the listener if it hasn't been added yet
  • Loading branch information
jennantilla committed Sep 4, 2024
1 parent d2539e2 commit dd3f899
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/android/com/onesignal/cordova/OneSignalPush.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,17 @@ private boolean preventDefault(JSONArray data) {
* N O T I F I C A T I O N C L I C K L I S T E N E R
*/

private boolean hasAddedNotificationClickListener = false;

public boolean addNotificationClickListener(CallbackContext callbackContext) {
OneSignal.getNotifications().addClickListener(this);
jsNotificationClickedCallback = callbackContext;
return true;
if (this.hasAddedNotificationClickListener) {
return false;
}

OneSignal.getNotifications().addClickListener(this);
jsNotificationClickedCallback = callbackContext;
hasAddedNotificationClickListener = true;
return true;
}

@Override
Expand Down

0 comments on commit dd3f899

Please sign in to comment.