UWP Toasted notification invoked OnBackgroundActivated multiple times


  • [Ref]

    Hi All,

    Microsoft given a code example to use background toasted notifications.

    If you try the same example locally, you will observer that OnBackgroundActivated method get invoked multiple times. 

    If you invoke the toasted notification and lock the windows and  press order button then `OnBackgroundActivated` method get invoked (In my case 5 times with same argument).
    After that even if you unlock the windows, `OnBackgroundActivated` method get invoked multiple times.

    Is that a bug or there are any workaround to fix this issue. I have to keep my toasted notification on the screen because of that i want to use `Background` `ActivationType` with 
    `PendingUpdate` as `ActivationOption`

    Can someone help me to understand why this is get called multiple times.

    Wednesday, March 13, 2019 7:55 AM


  • Hi,

    Well, there is an error in the sample code. In the App.xaml.cs, the background is register for multiple times because the if check sentence is checking for a wrong background task name.

     private void RegisterBackgroundTasks()
                // Actually the background task name registered is 'MyToastNotificationActionTrigger'
               // const string taskName = "ToastBackgroundTask";
               // so it should be like this:
                const string taskName = "MyToastNotificationActionTrigger";
                // If background task is already registered, do nothing
                if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName)))
                // Create the background task
                BackgroundTaskBuilder builder = new BackgroundTaskBuilder()
                    Name = "MyToastNotificationActionTrigger",
                // Assign the toast action trigger
                builder.SetTrigger(new ToastNotificationActionTrigger());
                // And register the task
                BackgroundTaskRegistration registration = builder.Register();
    I suggest that you need to uninstalled the sample from your device and then run the sample again. It should works correctly in that time.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, March 14, 2019 9:57 AM