How to exit or quit my Windows Phone 8 app programmatically?
Asked Answered
K

3

9

I am developing a Windows Phone 8 application.

  1. How can I exit or quit programmatically (through code) from my Windows Phone 8 app?

  2. What are the various ways in which I can programmatically (through code) exit or quit from my Windows Phone 8 app?

Kylander answered 24/2, 2013 at 13:42 Comment(1)
possible duplicate of Windows Phone 7 close applicationMonjan
E
33

In WP8 there's a new API which lets you terminate the application:

Application.Current.Terminate();

By calling the method your app will immediatelly terminate. However the Application_Closing event won't be called, and IsolatedStorageSettings.ApplicationSettings dictionary won't be automatically persisted.

So if you have data hanging around in IsolatedStorageSettings.ApplicationSettings that you don't want to lose then it's wise to save it:

IsolatedStorageSettings.ApplicationSettings.Save();
Application.Current.Terminate();

Also the method should not be misused. See http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.terminate(v=vs.105).aspx for more info for legitimate use cases.

Emblazonment answered 24/2, 2013 at 14:33 Comment(0)
D
2
while (((PhoneApplicationFrame)App.Current.RootVisual).CanGoBack)
{
    ((PhoneApplicationFrame)App.Current.RootVisual).RemoveBackEntry();
}
Duramen answered 25/2, 2013 at 8:26 Comment(1)
Great answer! I modified this to use while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry(). Is there a difference? It seems to do the same thing.Yorgen
T
0

In Windows Phone 8.1, the method has been renamed to

Application.Current.Exit();
Trochanter answered 21/11, 2015 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.