Browse DevX
Sign up for e-mail newsletters from DevX


Develop for the SmartPhone Using Techniques You Already Know

The form factor is new, but developing applications for these cutting-edge devices is mostly old hat. Armed with just a few additional principles and warnings, you can be making apps for SmartPhones long before the rest of the pack.

martPhones are the new devices that are said to be the death knell of the PDA and its clones. You can leverage your existing .NET skills and be among the first developers making expert apps for the SmartPhone. This article will get you familiar with the SmartPhone development environment, covering all the basics and revealing the pitfalls you need to watch out for. In it, you'll learn to build a simple application that consumes a Web service that looks up stock quotes.

Understanding the device is the first step to building SmartPhone applications. Figure 1 shows a typical SmartPhone device and its key features.

Figure 1. SmartPhone Hardware: Get familiar with the form factor before you begin.
As its name implies, the SmartPhone is a phone first, with PDA features added to it. Hence it has two very distinct send and end buttons to make or disconnect a call. The back key is a multi-function key, it acts like a backspace key when focus is in a text box and otherwise acts like a browser back button, moving to the previous screen/application in the display history.

There are two soft keys, and they are your application's best friends. They enable you to give options to your users. Soft keys are essentially programmable keys, the functions depend on the options you provide within your program. The central navigation controls provide the ability to tab/scroll and the center button is like an action button (Enter).

Before you can build SmartPhone applications using Visual Studio.NET 2003, you need to install the SmartPhone 2003 SDK. This provides a SmartPhone 2003 template.

Once you install the SDK, choose SmartDevice —>SmartPhone as the target platform to start building your project. You'll get a default form and a toolbox filled with new controls specifically for the SmartPhone as well as some grayed out controls that are not available for the SmartPhone. Figure 2 is a partial snapshot of the toolbox.

Figure 2. Device Controls: This is a partial list of the controls that Visual Studio offers for use with a SmartPhone project.
Figure 3. Simple Form with MainMenu Control: This menu has two items, Go and Options, with a submenu item Exit.
One of the first things I noticed is the absence of a Button control, which is typically used by the user to indicate action. There are two reasons for this absence, 1) the SmartPhone doesn't have a touch screen, and 2) there are alternate controls such as the menu, which allow the user to interact with the application. I discovered another problem when I tried to use the DataGrid control:it is completely unusable when you place it on a SmartPhone form.

Visual Studio will put a MainMenu control on your form by default. Use it to enable navigation, give user options, and allow the user to interact with your application. But the MainMenu is a bit too flexible for its own good: It doesn't enforce a limitation of top-level options when building a menu. But if you add too many the application will crash. In fact, you can have only two top-level menu items, but each of those can have n-number of options (see Figure 3).

Author's Note: Microsoft recommends that you do not use an exit option in your applications, as it is preferable to let the OS handle the shutting down of applications on low memory conditions. However during development and testing it is good have such an option. If you don't, you won't be able to shutdown and hence redeploy the application on the physical device as the application would still be running, causing a violation. The typical code behind the exit button would be to clear resources and enter code such as Application.Exit.

Thanks for your registration, follow us on our social networks to keep up-to-date