HTML and CSS Reference
In-Depth Information
chapter
5
Life-Cycle Events
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
Problem
Solution
Listing
Subscribe to events from the Windows.
UI.WebUI.WebUIApplication object.
Ensure that your app receives the
suspending and resuming events.
1
Create a recurring background task.
Use the WinJS Promise object as a wrapper
around other asynchronous activities.
2, 3
Call the suspendingOperation.getDeferral
method on the event passed to your
suspending handler function.
Request more time before your app
is suspended.
4
Implement a contract.
Declare the contract in the manifest and
respond to the type information in the
activation event.
5, 6
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
load and process your content and JavaScript and signal when everything is ready. It is during
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.
 
 
Search WWH ::




Custom Search