VS2010: Mobile development
By Tim Anderson
Visual Studio 2010 targets mobile devices, the mobile Web and embedded platforms
HardCopy Issue: 52 | Found In: Visual Studio 2010 | Published: 01/05/2011 | Last Revision: 29/06/2011
Debugging a Windows Phone 7 application.
Mobile development is hot. Powerful smartphones and tablets with Wi-Fi and 3G Internet connections are capable clients, and provide a ready market for apps. Devices like these will meet an increasing proportion of our computing needs, and there is strong demand for creating or extending both business and consumer applications to include mobile.
Microsoft’s approach to mobile development has two strands. The first is based on Windows Phone, the new Windows smartphone which was launched in October 2010. Microsoft targeted consumers rather than businesses with its first release of Windows Phone, but even its first release with support for Office and SharePoint suggests some overlap, and more business-focused features are expected in future updates. Note that devices running the old Windows Mobile operating system are still available, but to develop for them you must use a Smart Device project in Visual Studio 2008, not Visual Studio 2010.
The second strand is developing for the mobile Web. Using ASP.NET, you can create Web applications that detect which mobile browser is being used and deliver Web pages that are optimised for its characteristics.
The mobile Web
The difficulty with supporting mobile devices is that there are so many variations, from tiny Web browsers on feature phones to mobile Web browsers that are nearly as advanced as those on the desktop, but with smaller screens. Building a site that takes no account of mobile browsers is likely to result in a site that most mobile users cannot easily use, while redirecting mobile browsers to a very basic version may frustrate users of high-end smartphones.
Windows Phone 7.5 'Mango'
At the Mix conference in Las Vegas, Microsoft announced details of the next version of the Windows Phone operating system, codenamed ‘Mango’. New features include:
- Internet Explorer 9, including hardware acceleration, much faster JavaScript, and a substantial subset of HTML 5. This is a key enhancement, as it puts Windows Phone on a par with Android and Apple iOS devices as a client for Web applications. It also enhances applications that use the HTML or JavaScript runtime for part of their functionality.
- Around 1,500 new APIs with a runtime based on Silverlight 4.0 rather than 3.0.
- Fast application switching. Apps may remain in memory when the user switches away.
- Live Agents which can perform background tasks. This is a form of multi-tasking designed to meet developer needs while protecting overall performance.
- SQL Server CE on the device with LINQ (Language Integrated Query) access.
- A single application can own multiple Live Tiles.
- TCP/IP Socket support.
- Access to raw camera data for custom image processing.
- The ability to register apps with search for integration between Bing searches and your application.
The best solution is to take account of a range of devices. ASP.NET gives you the flexibility to do as much or as little as is appropriate. Note that ASP.NET Mobile Controls are no longer recommended as they are geared to deliver WML (Wireless Markup Language) or cHTML (Compact HTML), whereas today’s mobile devices expect HTML and CSS.
Web designers may be able to design mobile-friendly pages using client-side techniques like CSS 3 media queries which let you use different CSS for different screen sizes and orientation. This is unlikely to be sufficient on its own, and there is no substitute for detecting devices on the server and sending customised content. You can do this easily in ASP.NET by using a separate master page, or an entirely separate site, for each category of device you decide to support. If you are using ASP.NET MVC, you can have different views, or different controllers and views.
ASP.NET does browser detection using browser definition files, the implication being that these must be constantly updated in order to deal effectively with the latest devices. An open source library called 51Degrees.mobi Foundation addresses this by linking to the internet mobile device database WURFL. The library also adds an HttpModule to IIS that enhances the Request.Browser object used in ASP.NET to report browser capabilities, and redirects requests to mobile versions according to your settings in the Web.config configuration file.
Another recent development is jQuery Mobile, currently under development. jQuery Mobile offers a range of user interface widgets designed for mobile browsers and touch control. While it works with both ASP.NET Web forms and ASP.NET MVC, the MVC approach is a better fit. Further, for mobile development the lightweight ASP.NET MVC framework has performance advantages.
Part of the challenge of supporting mobile clients is testing. While there is no substitute for using actual devices, emulators are also convenient and useful. Emulators generally come as part of the mobile SDK for each platform, so for example to get Android emulators you need to install the Android SDK. The Windows Mobile Developer Took Kit includes emulators for Windows Mobile, and the Windows Phone Developer Tools include an emulator for Windows Phone 7.
Note that for emulators to be able to access your Web site, you must use Internet Information Server (IIS) rather than the built-in Web server, as each emulator runs in its own virtual machine.
Targeting Windows Phone
Microsoft’s Windows Phone platform is a fresh approach to Windows on mobile devices. Although the underlying operating system is still Windows CE, the user interface is a new design called Metro which looks radically different. The name was apparently inspired by a metro transport system that is clearly signed so you can easily find your destination. Metro has a focus on bold, modern typography, tiles, and on-screen views that can be a portal into a bigger virtual screen that lies behind. Some Windows Phone apps feature cut-off text on the right, and while this may look odd, it is a strong visual hint that more content is available if the user swipes the screen. Although Windows Phone 7 has had limited success in its first release, there is broad agreement that the user interface works well and represents a significant improvement on Windows Mobile.
Embedded Development
Gadgets like smartphones and tablets may grab more attention but embedded development is equally dynamic, and a world of opportunity for businesses looking for new approaches to marketing or more efficient ways of working. An example is the point of service area where improvements in usability, advanced bar code scanning and touch screens, enable innovations such as self-checkout terminals in supermarkets. Embedded development touches almost every area of home and business.
Windows is a popular choice for embedded development for several reasons. One is that it offers developers the familiar Visual Studio IDE with C/C++ or .NET languages. Another is that embedded devices generally need to integrate with other systems, and in organisations running Active Directory, SQL Server, Dynamics or other Microsoft systems, having Windows on the embedded devices makes it easier.
Currently there are two base systems for Windows Embedded: Standard 7 which is built on Windows 7; and Compact 7 which is Windows CE, suitable for the smallest devices. Both systems are componentised, so you only install the parts that you need. Silverlight for Windows Embedded lets you build rich touch-enabled user interfaces.
Microsoft also has specialised embedded products, including POSReady for point of service, Automotive 7 for vehicles, Embedded Handheld for rugged devices, and Embedded Enterprise, Server, and Thin Client for a range of applications. Windows Embedded Device Manager is an extension to System Center that assists in managing devices across the enterprise.
The best way to develop for Windows Embedded is through an MSDN Subscription. Visual Studio Professional Edition with MSDN Embedded includes Windows Embedded and Windows Server licences for test and development. Visual Studio Premium and Ultimate also include Windows Embedded.
Microsoft has outlined important new features for the next release (see panel on previous page) and Nokia has announced that it will be focusing on Windows Phone in future, so it is likely that its market share will increase. Further, there are hints that the design and application model in Windows Phone 7 may carry forward to some extent to the next version of Windows, especially on mobile form factors like tablets. In other words, it is worth investing time in learning Windows Phone development as this will be a key part of Microsoft’s platform.
The development platform is based on .NET, and specifically on Silverlight for general applications and XNA for games. XNA uses DirectX for hardware-accelerated graphics, and in the 7.5 release,you will be able to mix Silverlight and XNA content.
The distribution platform is a new version of Windows Marketplace. Users can browse, rate, review and purchase applications over the air. Windows Marketplace means that even small development houses can get wide exposure for their applications. Currently it is not possible to distribute apps other than via the marketplace, but Microsoft says this will be possible for internal applications in future. It is possible for developers to deploy apps to their own devices.
Getting started with Windows Phone development is a matter of downloading the Windows Phone Developer tools for an existing installation of Visual Studio 2010, or installing Visual Studio 2010 Express for Windows Phone. This installs the emulator as well as adding Windows Phone project types. Note that the developer tools have been updated since their first release, so check for the latest available version.
Since it is based on Silverlight or XNA, and the .NET Framework, developing for Windows Phone is a familiar process for those with existing .NET skills. That said, do not be deceived: there are many new factors when designing and coding an application for Windows Phone (or any mobile device). Mobile devices are more resource-constrained than PC applications.
A key point is that whenever the user switches away from your app, it may be terminated. If your app maintains any kind of state, then you have to save the state and restore it when the app is reactivated. The user has the illusion that the app continues to run, even though it does not.
Also important is the Windows Phone Live Tile. This is a distinctive feature that comes into play when the user has pinned your application to the home screen. You can update the tile with notifications, even when your app is not running. Windows Phone apps can also interact with features that are not usually relevant to desktop applications. Examples include the accelerometer, location information, the camera and the touch interface.
Despite these challenges, Microsoft has delivered excellent tools and resources for Windows Phone making the platform attractive for developers.