In this article I will talk about Fast Application Switching (FAS) feature of Windows Phone mango version which allows application to be in dormant state(in memory) even user opens different application. Resume or re-starting time of an application can be optimized by determing application is being activated from dormant or tombstoned state.
When one application is running and second application starts, the image of first application stays in the momory (dormant state) as long as possible. This helps the end user experience because the application activation from dormant (in memory) is always faster than tombstoned state.
Read Execution Model Overview for Windows Phone to know understand dormant and tombstoned state.
One can take advantage of dormant state only one can determine the application is restored from dormant or tombstoned.
Let's write some code to take advantage of Fast Application Switching feature of Windows Phone mango version.
Step 1: Create Silverlight for Windows Phone project.
Step 2: Open App.xaml.cs and create a class level variable isTombStoned.
public partial class App : Application { public static bool isTombStoned { get; private set; }
Step 3: Now modify Application_Activated method of App.xaml.cs like below. IsApplicationInstancePreserved property of ActivatedEventArgs will help to determine whether the application is activating from dormant or tombstoned. IsApplicationInstancePreserved is set to false if Tombstoned occurred otherwise in case of dormant state IsApplicationInstancePreserved will be set to true.
private void Application_Activated(object sender, ActivatedEventArgs e) { if (e.IsApplicationInstancePreserved) { isTombStoned = false; } else { isTombStoned = true; } }
Step 4: In MainPage.xaml add a TextBox.
< TextBlock Text="" Height="30" HorizontalAlignment="Left" Margin="10,125,0,0" Name="textFAS" VerticalAlignment="Top" FontSize="18" />
Step 5: Now in the constructor of MainPage.xaml.cs add below code.
public MainPage() { InitializeComponent(); textFAS.Text = App.isTombStoned ? "From Tombstoned" : "From Dormant State!"; }
Step 6: Now run the application, you will notice it will always show From Dormant State.

Step 7: To test the code when application is returned from Tombstoned state, Go to properties of the project and check "Tombstone upon deactivation while debugging".

Step 8: Now run the application, click on Window button of device and click on back button of the device.
You will notice Resuming....will appear on the screen, it means application is activating from tombstone.
Once application is actiavted you will see From Tombstoned on screen like shown below.

This ends the article of Fast Application Switching (FAS) in mango version of Windows Phone.
|