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.

ToastNotificationManagerCompat.OnActivated event not invoked when toast action triggered with a closed app

See original GitHub issue

Describe the bug

I am following the description, defined in Send a local toast notification from C# apps, for handling toast actions in a winui 3 app (packaged) and are using WindowsAppSDK-1.00-preview2. Everything works as described except when the app has been closed before the toast comes up and the user then clicks the toast (toast itself or a button in there):

  • The app is launched successfully,
  • The call to ToastNotificationManagerCompat.WasCurrentProcessToastActivated() returns true, but
  • The ToastNotificationManagerCompat.OnActivated event is not triggered.

Because the event is not triggered there is no possibility to find out which button the user has clicked on the toast.

Steps to reproduce the bug

Create a winui desktop app. Implement the code and manifest changes defined in Send a local toast notification from C# apps. Trigger a toast notification with a button inside the toast. Close the app. Click the button in the toast notification.

Expected behavior

The ToastNotificationManagerCompat.OnActivated event must be invoked.

Screenshots

No response

NuGet package version

No response

Windows app type

  • UWP
  • Win32

Device form factor

No response

Windows version

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JosHuybrighscommented, Oct 26, 2021

Thanks for trying this. I checked your solution and it turned out that I was using “CommunityToolkit.WinUI.Notifications” Version=“7.0.3” instead of “Microsoft.Toolkit.Uwp.Notifications 7.1.1”. It now works OK. It’s not always easy to find out which packages we can use, especially for Notifications. Choosing the CommunityToolkit seemed to be logical since it has this WinUI name in the namespace and I am using it on a WinUI Desktop project.

0reactions
michael-hawkercommented, Oct 29, 2021

FYI, we’ve just shipped our 7.1.1-preview3 release for 1.0-preview3 so these packages have all been updated as part of that: https://github.com/CommunityToolkit/WindowsCommunityToolkit/releases/tag/winui-7.1.1-preview3

Read more comments on GitHub >

github_iconTop Results From Across the Web

App crashes on launch when activated from Toast ...
Form the code you've posted, it seems you are handling activation from a toast notification with OnLaunched method. However.
Read more >
ToastNotificationManagerCompat.OnActivated not ...
OnActivated event is not triggered if a toast is clicked when the app is not running. The app is started and ToastNotificationManagerCompat.
Read more >
ToastNotificationManagerCompat Class
Gets whether the current process was activated due to a toast activation. If so, the OnActivated event will be triggered soon after process...
Read more >
Prevent opening the app again when clicking on toast ...
So to prevent showing the showing when you click on a toast while the app is closed, follow these steps: In the main...
Read more >
Toast Notification Manager | WinForms Controls
Toast Notification manager cannot display notifications if a user has disabled notifications (application-specific notifications or all notifications).
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