This article primarily focuses on a detailed explanation of the Windows Phone Application Lifecycle.

Applies to: Windows Phone 8 and Windows Phone OS 7.1 Devices

The possible scenarios and navigation in a Windows Phone Application are:

If you explore the App.xaml.cs, you can find four predefined event handlers such as:

private
void Application_Launching(object sender, LaunchingEventArgs e){}
private void Application_Activated(object sender, ActivatedEventArgs e){}
private void Application_Deactivated(object sender, DeactivatedEventArgs e){}
private void Application_Closing(object sender, ClosingEventArgs e){}

These event handlers will be fired when the app enters into various states. The states are Running, Not Running, Dormant, and Tombstone.

The following is an overview of what happens in the Windows Phone application life cycle.

image.jpg

Launching and Closing the App

The following describes launching and closing the app:

Note:

The debugger will keep running even when the application has stopped running.

image1.gif

Deactivation and Reactivation of the App

The following describes deactivation and reactivation of the app:

Note:

External events such as incoming call, lock screen or any other activities keeps your app in the dormant state.

So how to deal with Dormant?

The following describes how to deal with being dormant.

Resuming an app; Fast Application Switching

The following describes the resumtion of an app; Fast Application Switching:

Note:

Windows Phone OS 7.1 can maintain only up to 5 dormant apps in the history stack whereas Windows Phone OS 8 can maintain up to 8 dormant apps in the history stack.

From Dormant to Tombstone

The following describes the transition from Dormant to Tombstone:

So how will you find the app returning from dormant or tombstone?

You can use the following code.

private voidApplication_Activated(object sender, ActivatedEventArgs e)
{
if(e.IsApplicationInstancePreserved)
{
// Dormant - state ispreserved in memory
}
else
{
// Tombstone - state is cleared. Soneed to restore from ASD
}
}

Windows Phone Idle Detection

The following describes Windows Phone idle detection:

Fast Application Resume

In the Windows Phone OS 7.1, a fresh instance of the app is always launched when the user starts a new copy of the app that will cause all the classes and data tobe reloaded that slows down the app activation.

The following image explains what happens if FAR is not enabled.

image6.jpg

The following image explains what happens if FAR is enabled.

image7.jpg

Happy Reading :)