23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

function activated(eventObject) {<br />

if (eventObject.detail.kind ===<br />

Windows.ApplicationModel.Activation.ActivationKind.launch) {<br />

if (eventObject.detail.arguments !== "") {<br />

// Activation arguments are present (declared when the<br />

// secondary tile was pinned)<br />

eventObject.setPromise(WinJS.UI.processAll().done(function () {<br />

// Navigate to Scenario 5, where the user will be shown<br />

// the activation arguments<br />

return WinJS.Navigation.navigate(scenarios[4].url,<br />

eventObject.detail.arguments);<br />

}));<br />

} else {<br />

// Activate in default state<br />

}<br />

}<br />

}<br />

The page control (js/LaunchedFromSecondaryTile.js) receives the arguments string in the options<br />

parameter of both the processed and ready methods. In the case of the sample it just copies that string<br />

to the display:<br />

var page = WinJS.UI.Pages.define("/html/LaunchedFromSecondaryTile.html", {<br />

processed: function (element, options) {<br />

if (options) {<br />

document.getElementById("launchedFromSecondaryTileOutput").inner<strong>HTML</strong> += "" +<br />

"App was activated from a secondary tile with the following activation" +<br />

"arguments : " + options + "";<br />

}<br />

},<br />

ready: function (element, options) {<br />

}<br />

});<br />

Your own app, of course, will do something much more interesting with arguments!<br />

Managing Secondary Tiles<br />

In addition to the methods and properties to create secondary tiles, the SecondaryTile class has two<br />

static methods to generally manage your app’s secondary tiles:<br />

• exists Returns a Boolean indicating whether a secondary tile, identified with its tileId, is<br />

present on the Start screen. This tells you whether calling a requestCreate* method for a tile<br />

with that same tileId will replace an existing one. This is demonstrated in Scenario 4 of the<br />

Secondary tiles sample.<br />

• findAllAsync Retrieves a vector of SecondaryTile objects that have been created by the app.<br />

This will include any tiles roamed from another device (those created with the copyOnDeployment<br />

575

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!