Running location-tracking apps in the background for Windows Phone 8

05/20/2016

2 minutes to read

In this article

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

On Windows Phone, only one app runs in the foreground at a time. If the user navigates away from an app by pressing the Start button or by launching another app, the current app is suspended. If the new foreground app requires more memory than the suspended app, the suspended app may be terminated and tombstoned. For more information on the life cycle of Windows Phone apps, see App activation and deactivation for Windows Phone 8. On Windows Phone 8, a location-tracking app can continue to run in the background after the user navigates away, as long as the app continues to actively track location. This feature enables scenarios such as an app that provides turn-by-turn directions. For a walkthrough of creating a simple app that runs in the background, see How to run location-tracking apps in the background for Windows Phone 8.

Deactivation of apps running in the background

This section lists the conditions under which the operating system will deactivate an app running in the background. When an app running in the background is deactivated, the Deactivated event is raised just like a regular foreground application. Your app can check to see the reason for deactivation in the Deactivated event handler by checking the Reason property.

Best practices for apps running in the background

For apps running on mobile devices, power consumption is an important consideration. While your app is running in the background, there are steps you can take to reduce battery usage and therefore improve user satisfaction with your app. The example described in How to run location-tracking apps in the background for Windows Phone 8 shows you a simple way to turn off unnecessary features when your app moves to the background.

Minimize the number and frequency of network requests. When possible, you should group your requests and perform them in batches at intervals of one minute or more instead of performing single requests every few seconds.

Stop active Timer and DispatcherTimer objects if they are only used for foreground functionality such as UI.