Table of contentsGetting Started - 1
BRIEFThis article is the first in a series of getting started with Mono for Android articles, and introduces the Mono for Android platform. It is the first step in learning how to build Mono for Android applications and covers the fundamental concepts of what the platform is, what it can do, as well as general information on building for Android. This article is intended for those who are brand new to Android and/or the Mono for Android platform, but who have at least a basic familiarity with C# and .NET programming. Time to Complete: 30 Minutes Related Articles: Installing Mono for Android OverviewWhen considering how to build Android applications, many people think that Java is the only choice. However, over the past few years, an entire new ecosystem of platforms for building Android applications has emerged. These new solutions include Mono for Android, AppCelerator, PhoneGap, etc., just to name a few. Each of these platforms has a different feature set and each varies in its ability to write native applications – that is, applications that compile down to native code and that interop fluently with the underlying Java subsystem. For example, some platforms only allow you to build apps in HTML and JavaScript (such as Mono for Android is unique in that it combines all of the power of Java and adds a number of powerful features of its own, including:
Because of Mono for Android’s powerful and comprehensive feature set, it fills a void for application developers that want to use a modern language and platform to develop cross-platform mobile applications. Let’s dig into Mono for Android a bit to examine how it works. How Does Mono for Android Work?Mono for Android is a commercial product built on top of Mono, which is an open-source version of the .NET Framework based on the published .NET ECMA standards. Mono has been around nearly as long as the .NET framework itself, and runs on nearly every imaginable platform including Linux, UNIX, FreeBSD, Mac OSX, and others. Mono for Android was originally created by Novell and released in 2011; however, just after its release, most of the Mono (and Mono for Android) team formed a new company (Xamarin) as part of Novell’s restructuring. Novell then granted Xamarin a perpetual license to all things Mono and handed the Mono for Android reins over to Xamarin, who supports and continues to develop new Mono for Android releases. Mono for Android allows you to use C# and the .NET Base Class Library (BCL) to write native Android applications. This is accomplished by executing applications in an instance of the Mono runtime VM, which co-exists on devices along with Google’s Dalvik VM. When a Mono for Android application is built, three main steps occur:
Mono.Android.dllMono for Android application’s are built against a subset of the .NET BCL known as the Mono for Android Profile. This profile has been created specifically for Android and packaged in Mono.Android.dll. This is much like the way Silverlight (and Moonlight) applications are built against the Silverlight/Moonlight .NET Profile. In fact, the Mono for Android profile is equivalent to the Silverlight 4.0 profile with a bunch of BCL classes added back in. For a full list of available assemblies and classes, see the Mono for Android Assembly List. In addition to the BCL, Mono.Android.dll includes wrappers for nearly the entire Android Development Kit. This allows you to invoke ADK APIs directly from C#. Note: Mono for Android applications are compiled against the Mono for Android profile, just like Silverlight/Moonlight apps are compiled against theirs. This means that you will have to recompile off-the-shelf .NET assemblies and your C# source against the Mono for Android profile. RequirementsAll the tutorials presented here are based on the latest Mono for Android and Visual Studio 2010 or MonoDevelop. Installation is covered in the next tutorial. Additionally, if you want to deploy to a device, rather than just the Android Emulator, you’ll need a non-evaluation version of Mono for Android, which can be purchased at the Xamarin Store. App StoresUnlike other popular mobile platforms, Android takes a very open approach to app distribution. Devices are not locked to a single, approved app store. Instead, anyone is free to create an app store, and most Android phones allow apps to be installed from these third party stores. This allows developers a potentially larger yet more complex distribution channel for their applications. The Android Marketplace is Google’s official app store, but there are many others. A few popular ones are listed below: Developing for AndroidLike other mobile platforms, developing applications for Android differs significantly from developing traditional desktop applications. Mono for Android goes a long way toward bridging some of the gaps, but the reality is that Android applications have a unique architecture as a result of the fundamental design of the Android OS, and therefore have some very specific requirements and limitations. Let’s examine some of these now. MultitaskingThere are two significant challenges to multitasking (having multiple applications running at once) on a mobile device. First, given the limited screen real estate, it is difficult to display multiple applications simultaneously. Therefore, in Android, only one application is in the foreground at any one time. Second, having multiple applications open and performing tasks can quickly eat battery power. Because of this, Android has a very specific screen (activity) lifecycle framework that applications must adhere to in order to create responsive, well-behaved applications. For more information, see the Activity Lifecycle guide. Many Devices + Many Form FactorsUnlike iOS, which has a small set of devices, or even Windows Mobile 7, which only runs on approved devices that meet a minimum set of platform requirements, Google doesn’t impose any limits on which devices can run the Android OS. This open paradigm results in a product environment populated by a myriad of different devices with very different hardware, screen resolutions and ratios, device features, and capabilities. Because of this, it’s important to take into account different devices throughout the entire software development lifecycle:
Limited ResourcesMobile devices running the Android OS get more and more powerful all the time, but they are still mobile devices that have limited capabilities in comparison to desktop or notebook computers. For instance, desktop developers generally don’t worry about memory capacities; they’re used to having both physical and virtual memory in copious quantities, whereas in Android you can quickly consume all available memory just by loading a handful of high-quality pictures. Additionally, processor-intensive applications such as games or text recognition can really tax the mobile CPU and adversely affect device performance. Because of considerations like these, it’s important to code smartly and to deploy early and often to actual devices in order to validate responsiveness. Security ConsiderationsApplications in the Android OS all run under a distinct, isolated identity with limited permissions. By default, applications can do very little. For example, without special permissions, an application cannot send a text message, determine the phone state, or even access the Internet! In order to access these features, applications must specify in their application manifest file which permissions they would like, and when they’re being installed; the OS reads those permissions, notifies the user that the application is requesting those permissions, and then allows the user to continue or cancel the installation. This is an essential step in the Android distribution model, because of the open application store model, since applications are not curated the way they are for the iOS, for instance. For a list of application permissions, see the Manifest Permissions reference article in the Android Documentation. x86 EmulatorDesktop and laptop computers commonly use x86 architecture, whereas mobile devices typically use ARM. Likewise the Android emulator has traditionally only been available for ARM. With the release of the r17 (and above) Android platform tools, an x86 emulator is available for Android API level 10 emulators, offering faster performance. For information on setting up an x86 emulator with Mono for Android see Configuring the x86 Emulator. DistributionAll Android applications must be signed before being distributed. Developers sign their applications by using their own certificate protected by a private key. This certificate can provide a chain of authenticity that ties an application developer to the applications that developer has built and released. It must be noted that while a development certificate for Android can be signed by a recognized certificate authority, most developers do not opt to utilize these services, and self-sign their certificates. The main purpose for certificates is to differentiate between different developers and applications. Android uses this information to assist with enforcement of delegation of permissions between applications and components running within the Android OS. SummaryIn this tutorial, we got a good background on Mono for Android, including what it is, how it works, and what it can and can’t do. We also examined general considerations for building Android applications, including app design factors and distribution. In the next tutorial, we’ll run through how to install Mono for Android on your platform of choice. |