(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = 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.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
};
app.start();
})();
If the activation kind is launch and the previous state is notrunning or closedByUser, the app should start up with its default UI and apply any persistent settings (such as those in its Settings panel). With closedByUser, there might be scenarios where the app should perform additional actions (such as updating cached data) after the user explicitly closed the app and left it closed for a while.
If the activation kind is launch and the previous state is terminated, the app should start up in the same state as when it was last suspended.
For launch and other activation kinds that include additional arguments or parameters (as with secondary tiles, toast notifications, and contracts), it should initialize itself to serve that purpose by using the additional parameters. The app might already be running, so it won’t necessarily initialize its default state again.
When an app is not visible (in any view state), it will be suspended after five seconds to conserve battery power. This means it remains wholly in memory but won’t be scheduled for CPU time and thus won’t have network or disk activity (except when using specifically allowed background tasks). When this happens, the app receives the Windows.UI.WebUI.WebUIApplication.onsuspending event, which is also exposed through WinJS.Application.oncheckpoint. Apps must return from this event within the **five-second ** period, or Windows will assume the app is hung and terminate it.
function onSuspending(eventArgs) { /* Your code */ }
// addEventListener syntax
webUIApplication.addEventListener("suspending", onSuspending);
webUIApplication.removeEventListener("suspending", onSuspending);
// - or -
webUIApplication.onsuspending = onSuspending;
//////////////////
WinJS.Application.addEventListener("checkpoint", listenerName);
// - or -
WinJS.Application.oncheckpoint = listenerName;
The best practice is actually to save session state incrementally (as it changes) to minimize the work needed within the suspending event, because you have only five seconds to do it.