I can start an application using app-protocol feature in windows 10 and universal windows application. To do that first i declare a protocol in Package.appxmanifest file in application B then from my main application which call application A, run this code to run application B :
var success = await Launcher.LaunchUriAsync(new Uri("MyApplicationProtocolName:"));
But i face a problem, when main application is startup, i cannot lunch application B, how can i do that ?
The problem is that declaring the protocol itself is not enough for the application to respond to it. You also need to implement the protocol activation in app B:
public partial class App
{
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
Window.Current.Activate();
}
}
}
The initialization you need to perform in OnActivated
will probably be similar to OnLaunched
in case the app is not yet launched. In case the app is already running, you don't need to do anything special, it will just come to the foreground. In case it is not running, you have to create the main Frame
, initialize the Window.Current.Content
and then do Window.Current.Activate()
to activate the app.