IT tutorials
 
Mobile
 

Windows Phone 8 : Building Location Aware Apps - Getting Started with Location (part 2) - Background Location Tracking

1/27/2015 3:07:19 AM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

Background Location Tracking

In Windows Phone 7.5, apps that made use of location tracking were subject to events being lost when deactivated. When the app was dormant or tombstoned, PositionChanged event handlers would be discarded—lost forever, leaving the app without any knowledge of changes in location for the period before reactivation.

This has changed in Windows Phone 8, which allows only a single app to be in execution at any one time unless that app is a location tracking app, in which case it can continue to run in the background while a different app is running in the foreground.

To nominate your app as a location tracking app, add a BackgroundExecution element to the DefaultTask element in your project’s WMAppManifest.xml file, as shown:

<DefaultTask Name="_default" NavigationPage="MainPage.xaml" >
    <BackgroundExecution>
        <ExecutionType Name="LocationTracking" />
    </BackgroundExecution >
</DefaultTask>

With this in place, your app will continue to run as long as it remains subscribed to a Geolocator object’s PositionChanged event.

When your app is running in the background, it is important to stop all tasks not related to location tracking. To be notified when your app is running in the background, subscribe to the RunningInBackground event of the PhoneApplicationService. This can be done in your project’s App.xaml file as shown:

<Application.ApplicationLifetimeObjects>

    <shell:PhoneApplicationService
        RunningInBackground="HandleRunningInBackground"
        ... />
</Application.ApplicationLifetimeObjects>

The event handler is placed in your App.xaml.cs file, like so:

void HandleRunningInBackground(object sender, RunningInBackgroundEventArgs e)
{
    /* Stop all tasks not related to location tracking. */
}

The RunningInBackground event enables your app to suspend unnecessary tasks, such as updating the UI.


Note

Only one location tracking app can be running in the background at any time. The most recently opened location tracking app takes precedence and causes any existing location tracking apps to be made dormant or tombstoned.


Although location tracking apps are currently the only type of app that can be enabled to run in the background, plan to see other types of background apps in the future.

Testing Apps That Use the Geolocator

The Windows Phone emulator includes a tool for simulating location tracking, which can be accessed by clicking the Additional Tools button on the emulator menu , and then selecting the Location tab on the Additional Tools windows.

The location simulator works in two modes: a live mode that allows you to interact with the map to send location data to the emulator as soon as you click on the map and a playback mode that causes the location simulator to step through a sequence of map points, which you enter by clicking on the map (see Figure 2).

Image

FIGURE 2. Location simulator.

Map points can be saved to a file and loaded again at a later time.


Note

The Play button is enabled only when the Live button is toggled off.


When using the location simulator, any Geolocator instances in your app respond as though they are receiving actual location data, giving you the opportunity to test your app’s geo location features.

 
Others
 
- Windows Phone 8 : Building Location Aware Apps - Getting Started with Location (part 1) - Geolocator Class
- Windows Phone 8 : Building Location Aware Apps - Location Sensing Technologies
- Windows Phone 8 : Range Controls (part 2) - Progress Indicator, Slider , ScrollBar
- Windows Phone 8 : Range Controls (part 1) - ProgressBar
- Windows Phone 8 : Items Controls - ListBox, ComboBox
- Windows Phone 8 : LinkedIn (part 3) - Posting a Message, The Feeds Filter
- Windows Phone 8 : LinkedIn (part 2) - Accessing LinkedIn Content, Responding to a LinkedIn Post
- Windows Phone 8 : LinkedIn (part 1) - Configuring Your LinkedIn Account
- Windows Phone 8 : Twitter (part 2) - Checking for Tweets, Responding to a Tweet, Checking Twitter Notifications
- Windows Phone 8 : Twitter (part 1) - Configuring Your Twitter Account
 
Youtube channel
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
programming4us programming4us
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS