ONDotNet.com    
 Published on ONDotNet.com (http://www.ondotnet.com/)
 See this if you're having trouble printing code examples


Writing Cross-Platform Mobile Applications Using Crossfire

by Wei-Meng Lee, author of .NET Compact Framework Pocket Guide
07/12/2004

If you are a Microsoft developer familiar with the .NET Framework, you generally have two options if you want to write mobile applications. For mobile handsets, you can develop mobile web applications using the ASP.NET Mobile controls. For standalone applications, you can use the .NET Compact Framework. However, using the .NET Compact Framework, you can only target Pocket PC devices. And that essentially means that you are out of luck when it comes to developing for competing devices such as Palm and Symbian Smartphones.

A new product from AppForge (www.appforge.com), known as Crossfire, promises to close the gap. Using Crossfire, you can leverage on your familiarity with VB.NET (or Visual Basic 6) and write cross-platform mobile applications supporting a wide variety of devices. What that means to a developer is that you now do not need to use the proprietary SDK for each device platform -- you simply maintain one code base and it can then be deployed to multiple platforms.

Device Platforms Supported

Crossfire supports the following platforms:

Figure 1 shows some of the devices that are supported by Crossfire.


Figure 1. The Nokia 6600, palmOne Zire 72, Sony Ericsson P900, and HP iPaq 4150

Crossfire achieves its platform independence through the AppForge's Booster Virtual Machine (previously known as MobileVB). Booster is analogous to the CLR in the .NET Framework. Crossfire applications require the Booster in order to execute. Booster takes up a mere .5MB to 1.3MB of storage space, depending on the target device. On my Zire 72, it has a footprint of .8MB.

Note that only VB.NET and VB6 are supported in Crossfire, and Booster supports most of the commonly used functions in VB.NET.

Familiar Development Environment using Visual Studio .NET 2003

After installing Crossfire, Visual Studio .NET 2003 will add a new Crossfire Application template in the Visual Basic project type (see Figure 2).


Figure 2. The new Crossfire application template

You will then select a platform for which you want to develop (see Figure 3).


Figure 3. Select the target platform

You will see the familiar IDE (see Figure 4).


Figure 4. Using the Visual Studio .NET 2003 IDE to develop a Crossfire application

As in most .NET applications, you drag and drop controls onto the form. Crossfire includes a comprehensive list of controls in the Toolbox (see Figure 5).


Figure 5. The built-in controls of Crossfire (right-click to add more controls)

I have populated my form with some of the built-in controls (see Figure 6). It is identical to developing a .NET Compact Framework application.


Figure 6. Populating the form with AppForge controls

Besides the normal controls that you would expect to see in a mobile application (such as Button, Label, ListBox, etc), Crossfire also includes some interesting controls. Some controls that caught my attention are:


Figure 7. Using the SignatureCapture control for user signature

While you are not able to use the controls provided in the Windows Forms (only AppForge controls can be used), you can use the MainMenu control (in the Windows Forms) to create a menu (see Figure 8).


Figure 8. Using the MainMenu control in the Windows Form

When deployed on a Palm device, the menu looks like that shown in Figure 9.


Figure 9. The menu on the deployed application

Testing the Application

There are three ways to test an application:

  1. Press F5 and test the application on a Windows form. This is the most elementary form of testing and is useful for functional testing, but not ideal for testing the user interface.
  2. Install a device emulator and test the application on the emulator (see Figure 10). You can install emulators of platforms you are targeting and deploy the applications onto them. This is the most efficient way to test your application.
  3. Connect a real device to your computer and deploy the application onto the device. This should be done at the final stage of your application where you want to test the real-world usage of your application.


Figure 10. Configuring Crossfire to use an emulator for testing

For this article, I have tested my application on a palmOne Zire 72. As Crossfire applications require the Booster in order to work, you need to first of all install the Booster on the device. You can install it via the AppForge menu (see Figure 11).


Figure 11. Installing the Booster on the device

Once the Booster is installed, you can now deploy the application to the actual device (see Figure 12). The icon next to the platform name indicates that the device is designed for that particular platform, but you can still deploy it to the other platforms (although it is not guaranteed to work).


Figure 12. Deploying the application to a device

If you are deploying a Palm application for the first time, you need to supply a Creator ID (to learn more about the Creator ID, visit the URL shown in the dialog window, as shown in Figure 13. For this example, I just enter four random characters.


Figure 13. Setting a Creator ID for your application

To copy the application onto the device, perform a HotSync on your device. The application (DeliveryApp) now appears in the device (see Figure 14).


Figure 14. The DeliveryApp application deployed on the Palm Zire 72

Crossfire also supports building installation files for the various platforms (see Figure 15). For example, Crossfire builds .prc files for the Palm platform.


Figure 15. Building installation files for the various platforms

Learn Using the Sample Applications

Crossfire ships with six sample applications illustrating several techniques in using Crossfire running on multiple device platforms. Here are the six (descriptions are from the documentation):

  1. Animals (AFDatabase): The Animals AFDatabase sample demonstrates how to use the AppForge Database Model to gain generic access to the native database structures on various devices.
  2. Animals (PDB): This application demonstrates the basic functionality of the AppForge PDB Library. Use this Database Tutorial to learn how to add database functionality into your own Crossfire applications.
  3. Launch Pad: The Launch Pad sample provides a simple user interface to retrieve files from the file system on a device, and to launch applications. When testing the application in Windows, it looks for the folder C:\Program Files\AppForge. It then recursively scans that directory and all sub-directories for any file with the extension .exe. It lists all of those applications in the grid. When the user selects an application in the list and presses run, the selected application is launched.
  4. PIM Scheduler: The PIM Scheduler sample provides a simple user interface to view and modify the PIM (Personal Information Manager) data that is native to a given device. This example only interacts with the Scheduler (or Calendar), but the same techniques can be used for Contacts, Memo, and ToDo. To run this application in Windows, you must have Microsoft Outlook installed. This application will read and write to the same database that is used by Outlook.
  5. Proof of Delivery: The Proof of Delivery application confirms a delivery with a barcode scan and a signature capture. This information is written to a PDB, along with a time stamp, for storage.
  6. Stock Quote: The StockQuote sample provides a simple user interface to retrieve information about a publicly traded stock. It also allows a user to maintain a list of stocks in a portfolio. Current price information about a particular stock is retrieved from the Internet using a public site. The sample illustrates two different means of accessing this web site: through the AppForge InetHTTP control that specifically targets HTTP communication, and through the more general AppForge Socket control that allows full TCP/IP access.

Summary

I think Crossfire has a lot of potential. With many device platforms on the market, developers are having a hard time trying to adapt their applications to run on the different platforms. Having a single code base able to run on multiple platforms is definitely a cost-saving proposition. Moreover, AppForge has cleverly leveraged on developer's familiarity with the .NET language (VB.NET, in this case) and spared developers the need to learn a more cryptic language such as C++. If you have not tried Crossfire yet, get a 30-day evaluation from www.appforge.com.

Wei-Meng Lee (Microsoft MVP) http://weimenglee.blogspot.com is a technologist and founder of Developer Learning Solutions http://www.developerlearningsolutions.com, a technology company specializing in hands-on training on the latest Microsoft technologies.


Return to ONDotnet.com

Copyright © 2009 O'Reilly Media, Inc.