Application lifecycle

The applications running on the Windows Phone 8 operating system have a specific lifecycle, and understanding it is very important for developing applications and games. At any given time, each application is in one state and can change the state only if some particular circumstances exist. Such a concept of the application lifecycle is related to the assumption that only one application is running in the foreground at the same time. Thus, it is required to use some mechanism to suspend and resume other applications, as well as handle the states of particular pages inside them.

Available states of the application, as well as its events (marked as A) and page methods (indicated as P) are presented in the following diagram, based on http://msdn.microsoft.com/library/ff817008. It can be beneficial for further development to remember connections between states, events, and methods.

Application lifecycle

The application is, at a given time, in exactly one out of three states:

  • Running – The application is currently running
  • Dormant – The application is not running, but application remains in the memory
  • Tombstoned – The application is terminated, but the state dictionary and navigation data are preserved

It is worth mentioning that the Running state can be changed to Dormant, for example, when the player presses the Start button. The Dormant state can be replaced with Tombstoned. The Running state is accessible from both the Dormant and Tombstoned states.

Four events related to the application are available:

  • Launching – It is called when a new instance of the application is launched by the user, for example, by selecting its icon from the application list
  • Closing – It is called when the user navigates back past the last page of the application, for example, when the Back button is pressed twice, after launching the application and opening the Ranks screen
  • Activated – It is called when the game state is changed from Dormant (or Tombstoned) to Running
  • Deactivated – It is called when the game state is changed from Running to Dormant, for example, when the player presses the Start button or if the lock screen is activated

Note

The Launching event is not fired when the application returns from the Dormant state. The Activated event is not fired when a new instance of the application is launched. Thus, to perform some operations, every time when the state is changed to Running, you should handle both these events.

An implementation of the methods called when the application-related events are fired, is available in the App.xaml.cs file. Here, you can add your own code that is executed while the application is launching, closing, activating, or deactivating.

However, you can also perform some additional operations while the user navigates to or away from a particular page (for example, Menu or Ranks). To do this, you should override the OnNavigatedTo or OnNavigatedFrom methods, respectively, in a file with the C# code representing the given page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.226.66