How to exit or close an app for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

This topic describes methods and best practices for exiting or closing a Windows Phone app.

This topic contains the following sections.

User actions, events, and methods that exit or close a Windows Phone app

The following table lists the user actions, events, and methods that exit or close a Windows Phone app.

In the following table, state refers to the state dictionaries maintained by the PhoneApplicationService at the app level and by the PhoneApplicationPage at the page level.

User action, event, or method

Result

Events raised

Effect on back stack and state

User presses the Back button on the first page of the app.

The app is closed.

Closing

The app is removed from the back stack. State is not preserved.

User presses the Start button.

The app is deactivated.

Deactivated

The app remains on the back stack and state is preserved until one of the following events occurs:

  • The user launches the app again from the Start screen, or by any method other than the Back button.

  • The app is removed from the end of the back stack because the back stack is full.

  • The device is rebooted or the app is uninstalled.

An unhandled exception occurs.

The app is terminated.

None.

The app is removed from the back stack. State is not preserved.

The app calls the Terminate method.

The app is terminated.

None.

The app is removed from the back stack. State is not preserved.

Best practices for exiting or closing a Windows Phone app

Here are best practices for exiting or closing a Windows Phone app.

Let the Windows Phone operating system manage the app’s life cycle and resources.

You don’t have to worry about closing your app or releasing its resources.

  • When the user presses Back to exit your app, the app is closed.

  • When the user launches a different app, your app is deactivated and becomes dormant. If other apps require more resources, your dormant app is tombstoned.

The Windows Phone operating system handles these conditions and automatically manages the phone’s resources. For more info, see App activation and deactivation for Windows Phone 8.

Don’t use an exception to exit your app.

An unhandled exception in your app consumes resources unnecessarily both on the user’s phone and on the Windows Phone servers.

The phone generates and uploads crash dumps for unhandled exceptions to help you find and fix bugs in your code. Crashing your app to close it wastes the user’s battery power and network bandwidth.

Don’t provide a Close, Quit, or Exit button.

Users know that they can press Start or use the Back button to leave your app. You risk confusing users if you provide an option that’s inconsistent with the Windows Phone programming model and that they don’t see in other apps. For more info, see the following blog posts:

Manage the back stack and handle the Back button naturally.

As users navigate through your app, use the phone's Back button to return them to the most natural page in the app. This means that your app does not always return them to the previously viewed item. It also does not return them to the same page in all circumstances.

Consider these examples from the behavior of built-in apps:

  • After you tap on a reminder to view the reminder, Back returns you to your previous activity. It does not take you to the Calendar.

  • After you tap on a pinned item (that is, a secondary tile) to view a specific item such as a contact, Back returns you to the Start screen. It does not take you to the People hub.

During a transaction such as an online purchase that requires several steps, Back returns the user to the previous step while the transaction is in progress. After the transaction is complete, Back returns the user to the browsing experience. Use the RemoveBackEntry method to remove unwanted pages from the back stack when the transaction is complete. For more info, see How to navigate using the back stack for Windows Phone 8.

You can use several approaches to avoid saving pages on the back stack and thus simplify navigation.

  • For a series of detail items, browse items in place on a single page. Rebind controls to display the next item. Use app bar buttons to navigate from one item to another. The Back button returns the user to the list of items. For example, this is how the built-in email app works.

  • For transient UI such as an alert, consider using a Popup control. The Back button dismisses the popup window. To enable this behavior, handle the BackKeyPress event while the popup window is visible and set e.Cancel = true.

Never use the Back button to change the content of the current page or to navigate forward to new content.

For more info, see the following blog posts:

Why do you want to close your app?

This section discusses the reasons for which developers sometimes want to implement a Close button for their app.

Important Note:

For more info about the solutions recommended in this section, see the preceding section, Best practices for exiting or closing a Windows Phone app.

Reason to terminate an app

Recommended solution

The app can’t continue. For example, the user has declined the license agreement.

Let the user press Start or Back to exit the app.

Or, call the Terminate method.

The app is in an unstable state. For example, an unhandled exception has occurred.

Let the operating system terminate the app.

The user has navigated through a large number of pages. I don’t want to force the user to press the Back button so many times to exit.

Return the user to the most natural page in the app. For example, after the user navigates through a series of items, return the user to the list of items. Don’t force the user to step back through each item.

Consider adding a Home button to return the user to the app’s main page.

Or, let the user press Start to exit the app.

I want to release resources for use by other apps.

Let the operating system manage the app’s life cycle and the phone’s resources.

See Also

Other Resources

How to navigate using the back stack for Windows Phone 8

In-app navigation for Windows Phone 8