HTML and CSS Reference
In-Depth Information
A short note is worth mentioning about the setPromise method you see in the code snippet. The
method informs the application that some asynchronous work is in progress. The method that hosts
setPromise can't then be exited until the pending work is completed. However, processing continues
up to the end of the containing method. This creates the problem of how you can reliably decide
what to do once the pending work—also referred to as the promise—has terminated. The promise
object in WinJS has the then method that you use to specify any work to do upon completion of the
promise. Here's an example:
.then(function() { ... })
Another similar method also exists, named done. The difference between done and then is only
that then returns another promise object, whereas done doesn't return any value.
.then(function() { ... })
.then(function() { ... })
.done(function() { ... })
In summary, they do the same work but done can only be used at the end of a chain of actions.
Suspending an application
In Windows 8, only one application at a time can be active in the foreground. If the user switches to
a new application, then Windows 8 suspends the currently running application and moves it to the
background. The suspended application remains in memory even though its code doesn't run. The
checkpoint event is fired to the application when it is about to be suspended. Here's how you can
handle the event:
app.oncheckpoint = function (args) {
// Save app data in case of termination.
WinJS.Application.sessionState["location"] = ...;
During suspension you want to save any data that can help later to reconfigure a state of the
application very closely, if not identical, to the state when the application was suspended. You use
the sessionState dictionary to save values. The sessionState dictionary has a list of named entries—for
example, location, and takes string values. The name of entries is arbitrary, but usually an indicator of
the role of the saved data.
The user can switch back to a suspended application at any time; when this happens Windows just
wakes up the application, which regains the foreground at the expense of the current application.
Search WWH ::

Custom Search