HTML and CSS Reference
In-Depth Information
I create duplicate bindings and event handlers if I call
performInitialSetup
when my app
is already running. All sorts of odd behaviors emerge when this happens, but the most visible
problem is that the right column in the layout contains two sets of content because I end up
calling the
WinJS.Pages.render
method too many times. By contrast, if I fail to call
perform-
InitialSetup
when my app wasn't running, then I don't have any bindings and event handlers
and I don't display any content at all.
I need to be careful to call the
performInitialSetup
function when my app hasn't been run-
ning and avoid calling it the function if it has. I do this by looking at the
previousExecutionState
property of the event passed to the
activated
handler function, which reports on the execution
state of my app just before the
activated
event was sent. The range of values for this property
is enumerated by
Windows.ApplicationModel.Activation.ApplicationExecutionState
, but
the only value I care about to solve this problem is
notRunning
, which tells me that the app is
being told to start up as well as deal with the search:
…
if (e.previousExecutionState == actNS.ApplicationExecutionState.notRunning) {
performInitialSetup(e);
}
…
Testing the Search Contract
To test the contract, start your app. It doesn't matter if you start it with or without the debugger,
and it doesn't matter if you exit or suspend the app after you start it. The key thing is to make
sure it is present on the simulator.
Next, switch to the Start menu. You app, if it was still running, will be switched to the back-
ground and, after a few seconds, will be suspended. To begin a search, just start typing. You
want to search for something that will make a match, so type
hot
(so that your search will match
against the hot dogs item in the grocery list).
As you type, Windows will automatically begin a standard search, looking for applications
whose names contain
hot
. You will see something similar to Figure
5-3
, since there are no such
apps in the default Windows 8 installation.
Figure 5-3.
Initiating a search
To switch to an application-specific search, click the app's name on the list below the search
box. This will send the search
activated
event to the app. For my example app, I have clicked
the MetroGrocer item in the list, and the
activated
event triggers my simple search handler,
the result of which can be seen in Figure
5-4
.
Search WWH ::
Custom Search