Application Lifecycle

Version: 1.1.0

Description

The Windows Phone execution model dictates that only a single application can be active at one time, the foreground application. Therefore when the user navigates away from your application, be it by choice or due to an unexpected event such as a phone call, the Windows Phone operating system terminates your application. When creating an application, you must take this into account and make sure your application can both preserve and restore its state. This lab focuses on presenting the application life-cycle and demonstrating proper handling of various life-cycle events.

Overview

The Windows Phone execution model governs the life cycle of applications running on a Windows Phone, from when the application is launched until it is terminated. The execution model is designed to provide end users with a fast, responsive experience at all times. To achieve this, Windows Phone allows only one application at a time to run in the foreground—the visible application with which the user interacts. This eliminates the possibility of users getting their devices into a state where multiple applications are running in the background competing over the same limited resources, resulting in sluggish performance and excessive battery draw-down.

The Windows Phone execution model maintains a journal of the applications and pages viewed by the user. This defines the path of the phone’s Back key, which gives the user the option to navigate back through different applications and pages. This is useful when an application accesses the web or other phone service, as the user can at any point simply tap Back to return to the previous experience.

As noted above, only a single application can run in the foreground and no third-party applications are allowed to run in the background. Therefore when the user navigates away from your application, either to a chooser like picture chooser or to a launcher like phone call, the Windows Phone operating system suspends your application for a limited time. If resources are required by the operating system, your application might even get terminated.

The procedure in which the operating system suspends an application’s process when the user navigates away from the application is called tombstoning. The operating system maintains state information about the application. If the user navigates back to the application, the operating system resumes the application process (or restarts it if it was terminated before) and passes the state data back to the application, where the user will be able to continue seamlessly from his last interaction point with the application.

This lab focuses on the tombstone (or tombstoning) aspect of the Windows Phone Application life cycle and its effects.

Objectives

At the end of the lab you will:

  • Be familiar with the tombstoning aspect of the Windows Phone 7 application life cycle
  • Understand how application launching, activation, deactivation, and closing events work
  • Create a simple Silverlight application that uses these techniques to save an application’s state while navigating away from the application and restore it upon returning to the application

Prerequisites

The following is required to complete this hands-on lab:

  • Microsoft Visual Studio 2010 Express for Windows Phone or Microsoft Visual Studio 2010
  • Windows Phone Developer Tools
    Note:
     All of these Tools can be downloaded together in a single package from https://go.microsoft.com/?linkid=9772716

Estimated time to complete this lab: 45 minutes.