Skip to content

[Bug]: OneSignal.Notifications.addClickListener getting called as many times as app gets hot restarted #899

@AchmadSyarippudin

Description

@AchmadSyarippudin

What happened?

I want navigate to specific page when notification was click.

so I added this code :

"OneSignal.Notifications.addClickListener((OSNotificationClickEvent event) {
print(event.notification.additionalData);
})"

Steps to reproduce?

1. onesignal Version 5.2 
2. Degugging on android emulator 
3. add this code "OneSignal.Notifications.addClickListener((OSNotificationClickEvent event) {
      print(event.notification.additionalData);
    });"
4. restart /  hot reload application
5. check console log data was print as many times as app gets hot restarted

What did you expect to happen?

my expectation "print" only appears when I was clicked notification.

OneSignal Flutter SDK version

5.2.0

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Code : 

 @override
  void initState() {
    //--- notification
    OneSignal.Debug.setLogLevel(OSLogLevel.error);
    OneSignal.initialize(Environment.oneSignalAppID);
    OneSignal.Notifications.requestPermission(true);
    OneSignal.Notifications.addClickListener((OSNotificationClickEvent event) {
      print(event.notification.additionalData);
    });
    super.initState();
  } 

Log : 
7
I/flutter (13699): {action_url: /order/detail?id=1032, icon: asset/Icons/2024-04-22-10512396440.png, description: Pembayaran tagihan BPJS Kesehatan 1 bulan : BERHASIL, title: Transaksi BPJS Kesehatan Berhasil, type: notif, category: BPJS Kesehatan, status: unread}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions