Search code examples
c#windows-phone-8windows-phonetile

how to get back to the tile page(start screen) after launching the ConnectionSettings Task in WP8


I am trying to launch the Connection settings task from the secondary tile. For that I am creating a tile and giving the uri as like

"ShellTile.Create(new Uri("/LaunchSettings.xaml", UriKind.Relative), standardTileData);".

In LaunchSettings.Xaml launching Bluetooth setting using URI Scheme. like

"await Launcher.LaunchUriAsync(new Uri("ms-settings-Bluetooth:"));"

But once settings launched if I click back button, its coming to the LaunchSettings.xaml. Not returning to the Start screen. How to achieve that?

Please advice.


Solution

  • You need to exit the application in the OnNavigatedToEvent, so add the following override to your LaunchSettings.xaml.cs file:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (e.NavigationMode == NavigationMode.Back)
            Application.Current.Terminate();
    
        base.OnNavigatedTo(e);
    }
    

    Note that this will not trigger for example the Application_Closing event (see this link: http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.terminate(v=vs.105).aspx).