How to close a Windows Phone 8.1 app

v.g. picture v.g. · Sep 2, 2014 · Viewed 9.8k times · Source

In WP7 and WP8 I just needed to clear the backstack in a page, then press Back button and the app is closed. In WP8.1 I do Frame.BackStack.Clear(), press Back and the app just minimizes.. How to kill it with Back button?

Answer

the_nuts picture the_nuts · Sep 2, 2014

You can add, in your main page definition:

Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;

Then

private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
    if (!e.Handled && Frame.CurrentSourcePageType.FullName == "YourApp.MainPage")
        Application.Current.Exit();
}

Warning: As others said, you should not use this and let the system handle the app closure. For example, if you use the Application Insights, I found that they are not sent to Azure when in Release mode