Skip to main content

Android meets .NET !!!

It is always fun for me to program in C# (besides C++). If so, how would I feel if I was able to program for Android in C#? You may be wondering what in the world I am talking about. Android development environment is all Java and open source stuff. How could this Microsoft thing fit onto it?

Well, it seems that some clever guys had huddled up and ported Mono for Android, developed .NET libraries for the Android SDK, and also supplemented it with a 'Mono for Android' project template in Visual Studio; and called it mono for android. Thus we end up writing C# code happily for Android.

After a bunch of installations, fire up your Visual Studio (2010) and you should be seeing a new project template 'Mono for Android' under C#.

Create a new 'Mono for Android' project, which by default comes with an activity - C# code.

Modified the orginal code to try starting a new activity from the default one...

The project layout for most of the part is similar to the native Android project. The layout resources files are named *.axml, and the strings.xml is really clean with named string constants with the ugly behind the scenes of ids and stuff in the Resource.designer.cs. The way to code is straight forward and needs no special explanation. A good to see thing for me was .NET coding style.

A similar set of addins and plugins have been developed for MonoDevelop too; although I did not try that.

It is really a wondrous thing to know, program and relish such an attempt. However, there are sad curves in the story:-
  • Mono for Android is available only for Windows (and Mac). It is not available for Linux.
  • The installation of the application from Visual Studio and application response for the few clicks is pig slow. It is not Visual Studio's fault. It seems Mono takes quite a bit of time for JITting. After each part of the code is JITed, the application response for that part is fairly ok, but not as good as Android's native\custom VM Dalvik.
  • The trial version does not allow deploying on the device. You can play around and deploy only on the emulator. If you want to use it on the device, it costs. Yes, it costs somewhere between $400-2500, depending on the licesing and support. Pretty expensive!
Try it out (the trial one or the full version if you are rich), at least for fun!


Rajagopal said…
Good article.

I think Mono For Android is a better option for learning, but if we are to go with real time project and later deploying on a device, Java is the better option, though we may not enjoy the luxuries as in VS and C#.

We have a project running here, which is planned to move to the Android platform in near future. Some folks here argue to go with Mono, but I feel down the road we might realize support will be limited. Mono claims they support Silverlight in Linux using Moonlight, but it has many pitfalls.
I did a study on porting our current .Net application to Android. Following is the summary.

.Net Support using Mono Android

Mono for Android enables developers to use Microsoft Visual Studio to create C# and .NET based applications that run on Android phones and tablets.

Developers can use their existing skills and reuse code and libraries that have been built with .NET, while taking advantage of native Android APIs.
Mono does not support Windows Form/XAML/Silverlight or Visual Basic.
To reuse existing .NET code with Mono for Android, you must recompile your libraries with Mono for Android base assemblies.
Mono for Android will support the C# language, garbage collection, multi-threading and many features of the core of .NET 3.5 including C# 3.0 and LINQ
The following assemblies are part of Mono for Android 1.0:
· mscorlib.dll

· System.dll

· System.Core.dll

· System.Json.dll

· System.Runtime.Serialization.dll

· System.ServiceModel.dll

· System.ServiceModel.Web.dll

· System.Web.Services.dll

· System.Xml.dll

· System.Xml.Linq.dll

In addition, the following Mono assemblies are part of Mono for Android 1.0:
· Mono.Security.dll

· Mono.Data.Sqlite.dll

· Mono.Data.Tds.dll

· Mono.Android.dll

And the following third party assemblies are part of Mono for Android 1.0:
· OpenTK.dll

Database Support:
SQLite is supported as Database which is serverless. XML is also supported.

Installation of MS Access & SQL Server is not possible. So MDF & MDB files are not accessible. However connecting Remote SQL Server database is possible using Web services.

It supports wireless communications using GSM mobile-phone technology, 3G, Edge, 802.11 Wi-Fi networks.
One should expect only the development platform and the runtime to be available in Android or any others. WinForms is native to Windows. Porting to Linux makes sense while porting that to Android does not since the underlying technique of window management is completely different.

I am not sure if we can take the road of Mono for Android. There may not be issues support wise but the performance of the application seems not to be proven.

Not all portings work well. For instance, there is Firefox and Opera for Android. Both suck. They may not be ported but rewritten. Not sure!

If someone has already treaded that road and made success, it would be safe for us to choose. Or if we are to choose, it should not be a critical project on which the company bets.

But it is really exciting to know about such attempts. And who knows it may turn out to be a big success one day.
Hi guys..I like your blog information.This is one of the well defined post. Thanks for your support.
garryfernandis said…
I think Nowadays rather than using Java applications Android applications are in great demand in market.
So Its great article to read here and with the help of screenshots it makes us better an iphone app
Asava Samuel said…
Here is a database compatible with MonoDroid:
Asava Samuel said…
Here is another database that is compatible with Mono:
Programmer can use their current skills and recycling program code and collections that have been built with .NET, while using local Android operating system APIs.

Popular posts from this blog

Passing CComPtr By Value !!!

This is about a killer bug identified by our chief software engineer in our software. What was devised for ease of use and write smart code ended up in this killer defect due to improper perception. Ok, let us go!CComPtr is a template class in ATL designed to wrap the discrete functionality of COM object management - AddRef and Release. Technically it is a smart pointer for a COM object.void SomeMethod() { CComPtr siPtr; HRESULT hr = siPtr.CoCreateInstance(CLSID_SomeComponent); siPtr->MethodOne(20, L"Hello"); }Without CComPtr, the code wouldn't be as elegant as above. The code would be spilled with AddRef and Release. Besides, writing code to Release after use under any circumstance is either hard or ugly. CComPtr automatically takes care of releasing in its destructor just like std::auto_ptr. As a C++ programmer, we must be able to appreciate the inevitability of the destructor and its immense use in writing smart code. However there is a difference between …

jqGrid: Handling array data !!!

This post is primarily a personal reference. I also consider this a tribute to Oleg, who was fundamental in improving my understanding of the jqGrid internals - the way it handles source data types, which if I may say led him in discovering a bug in jqGrid.

If you are working with local array data as the source for jqGrid, meaning you will get the data from the server but want the jqGrid not to talk to the server anymore, and want to have custom handling of the edit functionality/form and delete functionality, it is not going to be straightforward - you need to have a decent understanding of how jqGrid works, and you should be aware of the bug Oleg pointed in our discussion. I repeat this is all about using jqGrid to manage array data locally, no posting to server when you edit or delete, which is where the bug is.

$('#grid').jqGrid('navGrid', '#pager', { recreateForm: true, add: false, search: false, refresh: false, …

Offering __FILE__ and __LINE__ for C# !!!

Not the same way but we could say better.
Visual Studio 2012, another power packed release of Visual Studio, among a lot of other powerful fancy language features, offers the ability to deduce the method caller details at compile time.
C++ offered the compiler defined macros __FILE__ and __LINE__ (and __DATE__ and __TIME__), which are primarily intended for diagnostic purposes in a program, whereby the caller information is captured and logged. For instance, using __LINE__ would be replaced with the exact line number in the file where this macro has been used. That sometimes beats the purpose and doesn't gives us what we actually expect. Let's see.

For instance, suppose you wish to write a verbose Log method with an idea to print rich diagnostic details, it would look something like this.
void LogException(const std::string& logText, const std::string& fileName, …