HTML and CSS Reference
In-Depth Information
If the user switches back to a suspended app, then the third stage occurs: the applica-
tion is restored . The app is displayed to the user, and execution of the app resumes. Suspended
applications are not always restored. If the device is low on memory, for example, Windows may
simply terminate a suspended app.
Correcting the Visual Studio Event Code
Unfortunately, the code for handling the life-cycle events that Visual Studio adds to a project
doesn't work. It deals with activation and suspension quite happily, but it prevents the applica-
tion from being notified when it is being restored. Fortunately, there are several points in the
WinJS and Windows API where I can register to receive the life-cycle events, so my first task in
this chapter is to update default.js so that I am properly notified when my app enters all three
life-cycle stages. You can see the changes in Listing 5-1.
Listing 5-1. Registering for Life-Cycle Event Notifications
(function () {
"use strict";
Windows.UI.WebUI.WebUIApplication.addEventListener("activated",
performInitialSetup);
Windows.UI.WebUI.WebUIApplication.addEventListener("resuming", performResume);
Windows.UI.WebUI.WebUIApplication.addEventListener("suspending",
performSuspend);
function performInitialSetup(e) {
WinJS.UI.processAll().then(function () {
UI.List.displayListItems();
UI.List.setupListEvents();
UI.AppBar.setupButtons();
UI.Flyouts.setupAddItemFlyout();
ViewModel.State.bind("selectedItemIndex", function (newValue) {
var targetElement = document.getElementById("itemDetailTarget");
WinJS.Utilities.empty(targetElement)
var url = newValue == -1 ? "/html/noSelection.html"
: "/pages/itemDetail/itemDetail.html"
WinJS.UI.Pages.render(url, targetElement);
});
WinJS.UI.Pages.render("/html/storeDetail.html",
document.getElementById("storeDetailTarget"));
Tiles.sendTileUpdate();
Tiles.sendBadgeUpdate();
});
}
function performResume(e) {
WinJS.Utilities.query("#topRightContainer h1")[0].innerText="Resumed";
}
 
Search WWH ::




Custom Search