Mobile Corner

10 Reasons to Upgrade to the Windows Phone SDK 7.1

Why you should update your apps to target the "Mango" software development kit.

There are countless reasons to upgrade your existing apps to take advantage of the new features in the Windows Phone 7.5 "Mango" OS update, which became available to most Windows Phone 7 customers in late October. In this article, I'll cover 10 of those reasons and highlight a number of new features that you can leverage within your applications.

In order to use the new features, you have to download the latest development tools at create.msdn.com, or via the Web Platform Installer 3.0. This update gives you access to the new Windows Phone SDK 7.1, as well as continued support for building applications that target the original release of Windows Phone.

After downloading the new tools, the next step is to run the upgrade process from within Visual Studio. Simply right-click on the Windows Phone project that you want to upgrade in Solution Explorer; and select Upgrade to Windows Phone 7.1 from the shortcut menu. This process is not reversible so it's advisable to backup your application prior to running the upgrade.

At this point, it's a good idea to run through all test cases for your application to ensure that the upgrade process didn't break any functionality. Despite a high level of backward compatibility, in some cases, the new SDK behaves a little differently than the previous version, which can lead to defects within your application.

If a feature doesn't appear to work as described, or your application won't compile when you attempt to use a feature, it could be because the upgrade doesn't add a reference to mscorlib.Extensions. This library is referenced by all new Windows Phone SDK 7.1 projects, and it's recommended that you add a reference to this library to your application.

No. 1: New APIs
A feature that's quite often neglected in discussions about Mango is that the new SDK is based on Silverlight 4. This update brings with it a number of incremental improvements that just make life easier when you're developing applications for Windows Phone. Two such examples are support for string formatting within data-binding statements in XAML, and support for Command data binding, both illustrated in the following XAML snippet:

<TextBlock Text="{Binding CurrentDate,StringFormat='dddd, d MMMM yyyy'}" />
<Button Content="Run My Code" Command=
  "{Binding RunMyCode}" CommandParameter="{Binding}" />

The StringFormat parameter is used to determine the formatting that's applied to the CurrentDate value, in this case to display the date in a format similar to "Tuesday, 3 January 2011." The Command property of the Button is data bound to a property called RunMyCode, which should return an object that implements the ICommand interface. This interface defines a method CanExecute, which determines if the command can be executed, and thus the enabled state of the button, and an Execute method. Both of these methods accept a single parameter, which in this case you're passing in the data-bound object itself, using the CommandParameter attribute on the Button.

In addition to the multitude of APIs included with Silverlight 4, Mango includes new APIs to support a range of Windows Phone-specific functions such as accessing data from the Gyroscope, Compass and an aggregate Motion class. Other Tasks can be used to interact with the phone, and additional classes and properties provide information about the device itself and its network status.

No. 2: Fast Task Switching
The Mango update brings with it Fast Task Switching, allowing the user to switch between running applications. Prior to the Mango update, when the user navigated to another application, the previous application was tombstoned. With Mango, applications will stay memory resident in a dormant state (not running), making it much faster for the user to switch between applications.

Phones that have had the Mango update applied to them will continue to run existing Windows Phone 7 apps in the same way that they have in the past. Windows Phone 7 apps are tombstoned as soon as the user goes to another application. When the user returns to the app, it has to be re-loaded into memory, often resulting in a significant lag before it's usable.

In order for your app to take advantage of Fast Task Switching, you need to upgrade it to target the Windows Phone SDK 7.1. If you've correctly handled tombstoning in your Windows Phone 7 app, you probably don't have to change anything to take advantage of Fast Task Switching. However, you should test it to make sure that it can handle the user switching in and out of your application.

In a lot of cases, upgraded apps assume that they've been tombstoned and will attempt to re-load data. As the dormant state keeps the entire app in memory, if the app hasn't been tombstoned, it's not necessary to reload data. The IsApplicationInstancePreserved property on the ActivatedEventArgs argument of the Activated event (typically found in App.xaml.cs) can be queried to determine whether the app has indeed been tombstoned, like so:

private void Application_Activated(object sender, ActivatedEventArgs e){
boolwasTombstoned = !e.IsApplicationInstancePreserved;
}

No. 3: System Tray
Prior to Mango, third-party apps could only set the IsVisible property on the SystemTray to show or hide the system tray, which includes the clock and icons indicating battery and network connectivity. The system tray was hidden in most apps because it had either a solid black or white background that often conflicted with the color scheme of third-party applications.

The Mango update extended the SystemTray to include the ability to control Foreground and Background color, as well as the Opacity of the system tray. The SystemTray can also contain a progress bar with associated Text that can be used to indicate what's happening.

No. 4: Application Bar
With the original release of Windows Phone, the design guidelines issued by Microsoft discouraged the use of the Application Bar within a Panoramic layout. The Mango update does away with context-aware search (the Search button now always goes to Bing search). This update has led to the use of the Application Bar across all built-in hubs, in order to place a search button for context-aware search.

In some cases, this would have meant that the Application Bar would obscure or detract from the look and feel of the hubs. To counter this issue, the Application Bar now has two modes: Default, where the icon buttons are visible, and Minimized, where only the expansion ellipses are visible. The two modes are illustrated in Figure 1.


[Click on image for larger view.]
Figure 1. With the Mango update, the Application Bar now has two modes: Default, where the icon buttons are visible and Minimized, where only the expansion ellipses are visible.

No. 5: Pin to Start/Application Tiles
Rather than the pages of application icons that so many smartphone OSes support, Windows Phone has the Start screen, which is unique in that it's made up of a series of user-selected Live Tiles. Prior to Mango, a user could only select an application to pin to Start. This application would be represented by a single tile, unlike some of the built-in apps, such as Internet Explorer, which enables the user to "pin" multiple Web sites to Start. Mango not only introduces the ability for an application to pin multiple facets to Start, it also extends the Live Tile to optionally include a reverse side. If an application makes use of the reverse side, the phone periodically rotates the tile between the front and reverse faces.

No. 6: Background Image Decoding
The combination of Visual Studio and Expression Blend meant that it was possible for application developers to rapidly develop applications for Windows Phone. However, the devil is in the details. While it was easy to use a ListBox to present a list of items, it was quite difficult to make sure that ListBox scrolling always performed well. Scrolling may not be smooth for a number of reasons, but one of the most common has to do with the way that Images are rendered. Take a simple list of items, where each item is displayed using an Image and a TextBlock. Even such a simple example could perform poorly because the images being displayed are being decoded on the same thread in which scrolling and user interaction occurs.

A significant improvement in Mango means that the decoding of images can be offloaded to a background thread. To do this, you need to augment the XAML to specify the CreateOptions of the ImageSource, as shown in Listing 1.

In Listing 1, the CreateOptions for the BitmapImage element is set to BackgroundCreation, which means that the image will be downloaded if the source is a remote image and decoded on a background thread. As a result, decoding the image will not have a direct impact on the performance of the ListBox scrolling.

No. 7: Base Control Events
In the original release of Windows Phone, a lot of the base level controls, such as the listbox, included support for various gestures. However, if you wanted to capture when a user tapped on an image, you were in for a tough ride. Microsoft did provide the Silverlight Toolkit for Windows Phone, which included a GestureService that could be used to capture gestures, including Tap and Hold. Unfortunately, in a lot of cases, this library caused as many issues as it fixed.

With the Mango update, all controls that inherit from UIElement expose the events -- Tap, Hold and DoubleTap. This makes it much easier to intercept user input. Of course, if you want to capture more complex gestures, such as Flick or Pinch, you'll still need to use the GestureService or wire up your own logic based on the FrameReported event on the Touch class.

No. 8: Background Agents
In addition to introducing Fast Task Switching, the Mango update includes a number of background agents. Windows Phone only supports a single foreground application running at any time, but now your app can include one or more background agents that can execute even when the app is no longer in the foreground.

The first type of background agent is for playing audio in the background. Previously an application could only play audio via the MediaElement or using the SoundEffect class, while it was in the foreground. Now, using an agent that inherits from either the AudioPlayerAgent or the AudioStreamingAgent, an application can invoke a background agent that can be used to playback audio even when the application is no longer running. This feature integrates with the built-in music playback experience, meaning that the user will see the usual media controls in both the Music + Video hub and on the lock screen.

Your application may need to download data, which previously would've required the user to keep your application running during downloads. The BackgroundTransferService can be used to request data downloads or uploads. This feature can be particularly useful if an application needs to download large quantities of data as the requests can be constrained to only be invoked when the device is connected to a power supply and on Wi-Fi.

The last type of background agent is a ScheduledTaskAgent, which is invoked to perform either a Periodic Task roughly every 30 minutes, or a ResourceIntensiveTask when the device is idle and connected to a power supply. These tasks can be used to perform actions such as update Live Tiles, track location or even look for updates. They can also alert the user by invoking a toast notification via the ShellToast class.

No. 9: Structured Data (LINQ to SQL and UserData)
Silverlight on the desktop only supports reading and writing to Isolated Storage, which you can think of as a poor-man's file system. As Windows Phone apps often run in scenarios of limited or variable connectivity, it's important for most applications to cache data. The lack of any structured data storage has resulted in a number of attempts at object data stores and even a couple of ports of SQLite. The Mango update includes support for LINQ to SQL, which provides a managed wrapper over SQL CE. Despite some limitations imposed by the managed wrapper -- you can't access any of the native change tracking capabilities that SQL CE supports -- it does offer a significant performance improvement over other storage techniques.

The other aspect of structured data that was introduced with Mango is the ability for an application to iterate over the user's contact and appointment data. Previously an application had to invoke one of the chooser tasks to get the user to select a contact whose information would be returned to the application and there was no way to retrieve appointment data. The Microsoft.Phone.UserData namespace permits an application read-only access to this data, although there are significant restrictions around data coming from third-party social networks such as Facebook, Twitter and LinkedIn.

No. 10: Silverlight Toolkit
The last reason I'm going to touch on for upgrading to the Windows Phone SDK 7.1 and targeting the Mango update is that you can take advantage of the updated Silverlight Toolkit for Windows Phone 7. The toolkit is available at silverlight.codeplex.com, or via NuGet. It offers a wide selection of controls which closely resemble controls that you may see used throughout the core user experience on the phone. These include:

    vAutoCompleteBox
  • ContextMenu
  • DateTimePicker
  • HubTile
  • ListPicker
  • LongListSelector
  • MultiselectList
  • PhoneTextBox
  • TiltEffect
  • ToggleSwitch
  • Transitions
  • WrapPanel

I've highlighted just 10 reasons to upgrade your existing apps, and some of the exciting features included in the Mango update. By upgrading your apps to target the Windows Phone SDK 7.1, you can make use of these features within your current applications.

About the Author

Nick Randolph runs Built to Roam, a consulting company that specializes in training, mentoring and assisting other companies build mobile applications. With a heritage in rich client applications for both the desktop and a variety of mobile platforms, Nick currently presents, writes and educates on the Windows Phone platform.

comments powered by Disqus

Featured

Subscribe on YouTube