Note that there are some explanatory texts on larger screens.

plurals
  1. POapp.onactivated not firing depending on placement of app.start()
    primarykey
    data
    text
    <p>My understanding of the <code>WinJS.Application.start()</code> function is that it allows WinJS to queue up certain normal page initialization events to give you a chance to set up other data first in your <code>default.js</code> file. By calling the <code>start()</code> function at the end of <code>default.js</code>, WinJS then fires off all the queued events for you (such as the <code>activated</code> event).</p> <p>I'm trying to understand where everything fits in the life cycle, so I'm not clear why the first of the following examples works but the second doesn't. All I'm doing is updating the page title, which doesn't work as expected when I call <code>app.start()</code> after a 5-second delay:</p> <p>First, here's <code>default.html</code>:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script references...&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 id="pageTitle"&gt;Page of coolness...&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here's the first <code>default.js</code> example (which works as expected):</p> <pre><code>(function () { var app = WinJS.Application; app.onactivated = function () { document.getElementById("pageTitle").innerText = "Rock it!"; }; // This code *does* fire the onactivated event: // The page displays "Rock it!" in the page title app.start(); })(); </code></pre> <p>Here's the second <code>default.js</code> example (which doesn't work as expected):</p> <pre><code>(function () { var app = WinJS.Application; app.onactivated = function () { document.getElementById("pageTitle").innerText = "Rock it!"; }; // This code *doesn't* fire the onactivated event: // It initially displays "Page of coolness..." in the page title. // After 5 seconds, it adds "Gettin' there...Almost made it..." // to the the page title, but "Rock it!" never gets displayed WinJS.Promise.timeout(5000).then(function () { document.getElementById("pageTitle").innerText += "Gettin' there..."; app.start(); document.getElementById("pageTitle").innerText += "Almost made it..."; }); })(); </code></pre> <p>Why does calling <code>app.start()</code> after the 5-second delay cause the <code>activated</code> event not to fire?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload