v.g.
v.g.

Reputation: 1076

How to close a Windows Phone 8.1 app

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?

Upvotes: 12

Views: 9791

Answers (4)

Maaz Irfan
Maaz Irfan

Reputation: 81

you can simply create a button by using XAML and then add this code into your Main page xaml.cs

Application.Current.Exit();

Upvotes: 3

the_nuts
the_nuts

Reputation: 6054

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

Upvotes: 17

Iliya Dankov
Iliya Dankov

Reputation: 21

MSDN recommends to not close apps in Windows 8.1:

We recommend that apps not close themselves programmatically unless absolutely necessary. For example, if an app detects a memory leak, it can close itself to ensure the security of the user's personal data. When you close an app programmatically, the system treats this as an app crash.

https://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx#close

Upvotes: 2

MattyMerrix
MattyMerrix

Reputation: 11193

I think the above has been depreceated. Exit is now an event.

Try

Application.Current.Terminate();

Upvotes: 3

Related Questions