HTML and CSS Reference
In-Depth Information
Declaring the Location Capability
Apps must declare their need to access the location service in their manifest. Before running
the updated app, open package.appxmanifest , switch to the Capabilities tab, ensure that the
Location capability is checked and save the file.
Testing the Background Task
All that remains is to test that the background task is meshing properly with the life-cycle events.
The easiest way to do this is with the simulator, which supports simulated location data.
Start by defining a location in the simulator (one of the buttons on the right side of the
simulator window opens the Set Location dialog box into which you can enter a location).
Once you have specified a location, start the app, remembering to do so without using the
debugger. After a few seconds, you will see the location information displayed at the top of the
app window, as shown in Figure 5-2 .
Figure 5-2. Location information displayed as part of the MetroGrocer layout
Switch to the desktop and use the Task Manager to monitor the app until it is suspended.
While the app is suspended, use the simulator's Set Location dialog to change the location.
I have used the coordinates of the Empire State building for this example. If you want
to do the same, then use the Set Location dialog to specify a latitude value of 40.748 and a
longitude of -73.98.
Resume the example app. The resuming event will restart the background task, ensuring
that fresh data is displayed.
You may have to grant permission for the simulator and the app to access your location
data. There is an automated process that checks the required settings and prompts you to make
the required changes to your system configuration.
Implementing the Search Contract
he suspending and resuming events are important, but I want to return to the activated event
and show you how it can be used to get tighter integration between your app and the rest of
the Metro system. To do this, I am going to implement a contract , which is how Windows 8
Search WWH ::

Custom Search