×
Namespaces

Variants
Actions
Revision as of 08:15, 30 November 2012 by hamishwillee (Talk | contribs)

Application Life Cycle - Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search
Featured Article
18 Sep
2011

This article describes the Application Life Cycle for Windows Phone 7.5 (Mango).

WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
CompatibilityArticle
Created: SeemaB (17 Sep 2011)
Last edited: hamishwillee (30 Nov 2012)

Contents

Introduction

It is important for developers to know Application's Life Cycle so that they can understand well what they are developing and use the best practices, which in turn helps in building a quality product and minimizes repetitive development efforts.

Application Life Cycle

Events and States together make up for an application’s life cycle. In Mango, there are 4 application life cycle events (Launching, Deactivated, Activated, Closing) and 3 application states (Running, Dormant and Terminated). Events lead to change the application’s state.

Launch Event

  • This event is raised when the user starts an application.
  • Keep this event quick, as users like the application to get loaded quickly.
  • Don’t use heavy resource usage activities in this event.

Code for application launching

private void Application_Launching(object sender, LaunchingEventArgs e)
{
}

Running State

  • Once the application is launched it goes into Running state.
  • This state is on till the user doesn’t navigate away from application or the phone is in lock mode.

Win 7 Mango - Lifecycle.png


Deactivated Event

  • Once the user goes away from your application, this event is raised.
  • In this event application’s context (state) should be saved. Once reactivated this saved state should be restored by the application.

Code for deactivation

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}

Dormant State

  • Dormant state did not existed in the versions before Mango.
  • This state was added in Mango for fast application switching.
  • On the deactivation event the application goes into this state.
  • In this state, application’s processing is stopped but it stays in memory.
  • In case other active applications need more memory, the dormant applications can be tombstoned.

Tombstoned State

  • Once an application is terminated it goes into tombstoned state.
  • In this state the data/application state information is preserved for maximum 5 applications.

Activated Event

  • When user switch back to a dormant or tombstoned application, this event is fired.
  • Developer should check the IsApplicationInstancePreserved property to know if the application is returning from being dormant or tombstoned state.
  • If it’s value true, then the application was in dormant state else tombstoned state.

Code for application activated

private void Application_Activated(object sender, ActivatedEventArgs e) 
{
if(e.IsApplicationInstancePreserved == true)
{ // Dormant State
}
else
{ // Tombstoned State
}
}

Close Event

  • When the user navigates backwards from the first page of application, this event is fired.
  • Application gets terminated in this event and you get only 10 seconds to save any data if required.
  • Remember developers should not have an explicit exit button for application to maintain the consistency of Windows Metro flow.

Code for closing event

private void Application_Closing(object sender, ClosingEventArgs e)                {        
}
472 page views in the last 30 days.
×