WinJS.Application.sessionState object

2 out of 9 rated this helpful - Rate this topic

An object used for storing app information that can be used to restore the app's state after it has been suspended and then resumed.

Data that can usefully be contained in this object includes the current navigation page or any information the user has added to the input controls on the page. You should not add information about customization (for example colors) or user-defined lists of content.

Syntax


var mySessionState = WinJS.Application.sessionState;

Members

The sessionState object does not define any members.

Remarks

Any data stored in the sessionState object is automatically serialized to disk when your app is suspended. If your app is terminated and re-launched, the sessionState object automatically repopulates the data from the last suspend.

Note that if your app crashes or is terminated prior to successfully completing the suspension of the app, the sessionState object does not repopulate data when your app is relaunched.

Examples

The following code is taken from the Visual Studio Grid App project template. The sessionState object is set in the checkpoint event handler to preserve the of the app before it is suspended. When the app resumes, the navigation state information stored in the sessionState object is restored.


app.addEventListener("activated", function (args) {
    if (args.detail.kind === activation.ActivationKind.launch) {
        if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
            // TODO: This application has been newly launched. Initialize
            // your application here.
        } else {
            // TODO: This application has been reactivated from suspension.
            // Restore application state here.
        }

        if (app.sessionState.history) {
            nav.history = app.sessionState.history;
        }
        args.setPromise(WinJS.UI.processAll().then(function () {
            if (nav.location) {
                 nav.history.current.initialPlaceholder = true;
            return nav.navigate(nav.location, nav.state);
            } else {
                  return nav.navigate(Application.navigator.home);
            }
        }));
    }
});

app.oncheckpoint = function (args) {
    // TODO: This application is about to be suspended. Save any state
    // that needs to persist across suspensions here. If you need to 
    // complete an asynchronous operation before your application is 
    // suspended, call args.setPromise().
    app.sessionState.history = nav.history;
};


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Namespace

WinJS.Application

Library

Base.js

See also

Tasks
How to handle app activation
How to suspend an app
Reference
WinJS.Application Namespace
Samples
App activate and suspend using WinJS sample

 

 

Build date: 12/5/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.