Write once-run anywhere has been the dream of computer
scientists for decades. It’s a dream that has gone mostly unfulfilled in its
truest form although many would say Java comes very close. The Mono project
sought to realize this dream for C#
coders with their efforts on all the major OS platforms including iOS and, more recently, Android. MonoTouch and
MonoDroid were the two products from Novell that offered a C# alternative to
Objective C and Java, at least until Novell was sold to Attachmate a few
The sale ultimately led to the layoffs of the entire Mono
team and the forming of a new company named Xamarin. Plans were made to
totally rewrite the MonoTouch and MonoDroid products from scratch as Attachmate
retained all rights to the original products. All this changed on July 18th
when an announcement was made that Attachmate had assigned all stewardship of
the Mono stack and the commercial MonoTouch and MonoDroid products to Xamarin
along with all support responsibilities. The timing couldn’t be better as the
Monospace 2011 conference is scheduled for
July 23 – 25 at the Microsoft NERD center in Boston, MA. MonoDroid has been
renamed as Mono for Android.
One of the distinctions of the Mono for Android product
over the MonoTouch offering is the dependence upon Visual Studio 2010.
MonoTouch requires a Mac with Apple’s
iPhone SDK installed in order to create applications you can install and run
on iOS devices. Mono for Android is
delivered as an add-on to Visual Studio 2010 and depends only on the Android
SDK. It also works with MonoDevelop on both Mac OS X and Windows. You can
download a trial version allowing you to test drive the product by installing
into an emulator.
Installing Mono for Android couldn’t be easier. All you
have to do is download the installer .MSI file and execute it. Once it
completes, you’ll have an additional option available for creating new
projects (see Figure 1). Selecting the default creates a shell project that
generates a single button with an incrementing count for every time you click
it. This shell application does illustrate another thing about developing for
Android that is different from iOS and that is the user interface.
If you’re heavily dependent on building a user interface
(UI) using Visual Studio’s great designer tools, then you’re in for a big
letdown with Mono for Android. Everything at this stage of the game must be
built using code. That’s not to say there aren’t other methods. Native
Android applications use an XML-based layout with some similarities to XAML. That
being said, there is currently no support for Moonlight or Silverlight on
Mono, so XAML is not supported. There’s also no support for the
Tablet-specific Android APIs, so you’re pretty much stuck with Android 2.x
for now. The Mono for Android FAQ points to an open source project called
DroidDraw that does create Android compatible UI XML files.
Most programmers find sample code a great way to see how
to accomplish a particular task. The Mono for Android project has a repository on github
with a number of working samples for this very purpose. The Contact
Manager sample demonstrates a number of UI elements including a listview
and a simple check box (see Figure 2). It also shows how to interact with the
Android API to query for the list of contacts. The ApiDemo project includes a
number of examples of various UI elements.
Rejoicing could be heard all over the Internet with the
announcement of the agreement between Attachmate and Xamarin. Much angst and
energy was expended during the time of uncertainty. Hopefully, this will put
C# development on Android devices back on track with many more new
capabilities and enhancements to come.