WinUI 3 - How to Retrieve ActivatedEventArgs Multiple Times?

Lee Feng 156 Reputation points
2024-11-05T03:15:54.47+00:00

The documentation states that AppInstance.GetActivatedEventArgs

this method will only return the arguments the first time it is called in an app.

If a packed single-instanced WinUI 3 app is activated from a protocol multiple times, what approach can be used to retrieve the URL each time?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
801 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 10,041 Reputation points Microsoft Vendor
    2024-11-05T06:56:37.2633333+00:00

    Hi,

    Welcome to Microsoft Q&A!

    Could you please tell us how do you create the single-instanced WinUI app? Whether you followed the Doc: Create a single-instanced WinUI app with C#

    If so, you will define the DecideRedirection method. In the DecideRedirection method you could call AppInstance.GetCurrent().GetActivatedEventArgs() to get the current IActivatedEventArgs. And then you could get the url via the ExtendedActivationKind.Protocol.

    AppActivationArguments args = AppInstance.GetCurrent().GetActivatedEventArgs();
    ExtendedActivationKind kind = args.Kind;
     
     
    switch (args.Kind)
    {
         case ExtendedActivationKind.Launch:
             break;
         case ExtendedActivationKind.ToastNotification:
             break;
         case ExtendedActivationKind.VoiceCommand:
             break;
         case ExtendedActivationKind.File:
             break;
         case ExtendedActivationKind.Protocol:
             IProtocolActivatedEventArgs protocoldata = args.Data as IProtocolActivatedEventArgs;
             Uri uri = protocoldata.Uri;
     
             break;
         case ExtendedActivationKind.StartupTask:
             break;
         default:
             break;
    }
    
    

    Thank you.

    Jeanine

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.