Understanding the Application LifeCycle of your Silverlight Based Windows Phone 7 (WP7) Applications

Introduction

The Windows Phone 7 platform supports two programming models - Silverlight and XNA. To fully realize the ability to write responsive Silverlight-based WP7 applications, it is critical to understand the application life cycle.

4 Phases of WP7 Application Activity

In a Silverlight-based WP application, there are 4 different phases of the app activity:

  • Launch - User starts the application by pressing its icon
  • Reactivating application by using Back button after navigating to some other application
  • Reactivating application by using Back button immediately after navigating to some other application
  • Deactivation - switching to other application either by pressing Start button or the Back button

To make an application responsive at startup, minimize the actions which take place which help reduce the time it takes for the user to start interacting with the application.

In the application Launch case as well as in the tomb-stoning case, here is the flow of events which takes place and the recommended actions to take at phase:

  • Application constructor - Do not add code here except the default created by Visual Studio
  • Application Launch event - Do not add code here.
  • Page constructor - Assign the view model to the DataContext; also, subscribe to the PageLayoutUpdated event; set a flag indicating the ctor have been invoked
  • View Model Constructor - Do as little as possible here
  • OnNavigatedTo event - Do not block the UI thread. For any function to be called, use BeginInvoke or use a background thread. Here, you handle cases for application launch, and reactivating after tombstoning.
  • PageLayoutUpdated event - Here you have to unsubscribe to the PageLayoutUpdated event; for any additional execution, use BeginInvoke or background thread,
  • OneNavigatedFrom event - this event is only hit when you exit the application. Here, you save the state of the application and clear the flag that the constructor has been called.

If the application is activated but not tombstoned and is re-activated, there are only a couple of events which occur:

  • Activated event
  • OnNavigateTo event - (same as above)

The smaller number of events is because the objects are still in memory and hence the processing to restore state is lesser. Because the objects are still in memory, the OnNavigateTo event hardly takes time.

Summary

In this short article, we saw the different life cycle events which occur in a Silverlight-based Windows Phone application. Hopefully, you will find the information useful in designing fast responsive WP applications.



About the Author

Vipul Vipul Patel

Vipul Patel is a Software Engineer currently working at Microsoft Corporation, working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com

Related Articles

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Webinar on September 23, 2014, 2 p.m. ET / 11 a.m. PT Mobile commerce presents an array of opportunities for any business -- from connecting with your customers through mobile apps to enriching operations with mobile enterprise solutions. Join guest speaker, Michael Facemire, Forrester Research, Inc. Principal Analyst, as he discusses the new demands of mobile engagement and how application program interfaces (APIs) play a crucial role. Check out this upcoming webinar to learn about the new set of …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds