Storing State with Session State

If an app is suspended then the app does not lose state. However, if an app is suspended and terminated then the state of the app is lost. Any variables will lose their values and the app will start from scratch.

There is a special object, the WinJS.Application.sessionState object, which you can use to store state across app suspension. Anything you add to session state survives until the app is activated again.

The code in Listing 11.1 illustrates how you can use session state to store the user’s current game score.

LISTING 11.1 Using Session State (sessionState/sessionState.js)

(function () {    "use strict";    var _gameScore;    WinJS.Application.addEventListener("activated" ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.