HTML and CSS Reference
In this, the nal chapter in this topic, I show you how to take control of the Metro app life cycle
by responding to key Windows events. I show you how to fix the code that Visual Studio adds to
projects, how to properly deal with your app being suspended and resumed, and how to imple-
ment contracts that tie your app into the wider user experience that Windows 8 offers. Along the
way, I'll demonstrate the use of the geolocation feature and show you how to set up and manage
a recurring asynchronous task. Table 5-1 provides the summary for this chapter.
Table 5-1. Chapter Summary
Subscribe to events from the Windows.
Ensure that your app receives the
suspending and resuming events.
Create a recurring background task.
Use the WinJS Promise object as a wrapper
around other asynchronous activities.
Call the suspendingOperation.getDeferral
method on the event passed to your
suspending handler function.
Request more time before your app
Implement a contract.
Declare the contract in the manifest and
respond to the type information in the
Dealing with the Metro Application Life Cycle
In Chapter 1 , I showed you the skeletal code that Visual Studio placed into the default.js le
to give me a jump-start with my example project. This code handles the Metro application life-
cycle events , ensuring that I can respond appropriately to the signals that the operating system
is sending me. There are three key stages in the life of a Metro app.
he rst stage, activation , occurs when your application is started. The Metro runtime will
activation that I generate the dynamic content for my example app, for example.
Users don't typically close Metro apps; they just move to another application and leave
Windows to sort things out. This is why there are no close buttons or menu bars on a Metro UI.
A Metro app that is no longer required is moved into the second stage and is suspended . While
suspended, no execution of the app code takes place, and there is no interaction with the user.