Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP app can't fully launch another UWP app?

The UWP app I'm working on uses Launcher to launch another UWP app that I also wrote. Here's the code I'm using to launch the other app:

        var uriToLaunch = "testapp-mainpage://";

        var uri = new Uri(uriToLaunch);

        bool success = await Windows.System.Launcher.LaunchUriAsync(uri);

So far, this code is able to launch the other app I wrote, but it just opens up the app window with the default blue background with an X in the middle, basically the default UWP splash screen. I've tried setting the URI to target the MainPage of the app, but no matter how I try to modify the URI, it just launches to the default splashscreen. The app I'm launching is just a very basic, default UWP app at the moment. What am I missing or doing wrong that it the app being launched doesn't fully initialize?

like image 420
Generalkidd Avatar asked Mar 10 '23 14:03

Generalkidd


1 Answers

You need to modify the launched app to handle protocol activation. The default wizards generate an app.xaml.cs which handles typical activation via OnLaunched but not alternate activations via OnActivated:

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.Protocol)
    {
        ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
        // TODO: Handle URI activation
        // The received URI is eventArgs.Uri.AbsoluteUri

        // You'll likely want to navigate to a page based on AbsoluteUri
        // If you just want to launch the main page you can call essentially
        // the same code as OnLaunched
    }
}

See Handle URI activation on MSDN for more details. See the Association Launching Sample for a concrete example.

like image 93
Rob Caplan - MSFT Avatar answered Mar 20 '23 13:03

Rob Caplan - MSFT