Geeks With Blogs
Bill Osuch - Random geek notes

It's been in an invitation-only beta for a while, but now you can download Mono for Android and develop Android apps in C# and Visual Studio 2010.

From the web site:

What is Mono for 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.

Mon requires:

  • Java JDK
  • Android SDK
  • Visual Studio 2010 (Professional or better) or MonoDevelop
  • The Mono for Android SDK

You should already have the first two if you're developing for Android, so go to http://mono-android.net/ and download the evaluation version. The install process is very simple - just click to execute and let it run.

Once it's finished installing, fire up VS2010 and you should see a new project type: Mono for Android Application. Creating an empty project gives you a solution with a directory structure similar to what you'd get in Eclipse - Assets and Resources folders, and an activity file called Activity1.cs.

The Mono site has several tutorials that are almost identical to those on android.com, so let's take a look at the Gallery tutorial:

Java version: http://developer.android.com/resources/tutorials/views/hello-gallery.html

Mono version: http://mono-android.net/Tutorials/Hello_Views/Gallery

First, you'll notice that the resource file is the same on both systems.

Now, look at the OnCreate method. Here's the C# version:

protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);

    // Set our view from the "main" layout resource
    SetContentView (Resource.Layout.Main);

    Gallery gallery = (Gallery) FindViewById<Gallery>(Resource.Id.gallery);

    gallery.Adapter = new ImageAdapter (this);

    gallery.ItemClick += delegate (object sender, ItemEventArgs args) {
        Toast.MakeText (this, args.Position.ToString (), ToastLength.Short).Show ();
    };
}

And here's Java:

@Override
public void onCreate(Bundle savedInstanceState) {
    
super.onCreate(savedInstanceState);
     setContentView
(R.layout.main);

    
Gallery g = (Gallery) findViewById(R.id.gallery);
     g
.setAdapter(new ImageAdapter(this));

     g
.setOnItemClickListener(new OnItemClickListener() {
        
public void onItemClick(AdapterView parent, View v, int position, long id) {
             Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
        
}
     
});
}

Pretty much the same...

So, if you're a C# developer who really doesn't want to mess with learning Java, this might be the way to go. The drawback is cost... First, you'll need a Visual Studio Professional license (in the neighborhood of $700), although you could try using MonoDevelop (free). The real expense is in Mono itself. Even if you only want the Professional version (which is unable to do large-scale deployments to 100 or more devices) you're looking at $399. There's a $99 Student version, but it can't be used commercially and can't deploy to any market. Also, that license only entitles you to a year of updates of Mono.

Personally, as much as I'd like to recycle some existing C# code, I don't think this IDE would ever be worth $399 to me as a hobbyist developer.

Technorati Tags: Android

Posted on Friday, April 8, 2011 1:01 PM Visual Studio 2010 , Android , C# | Back to top


Comments on this post: Android - Create apps in Visual Studio / C# with Mono

# re: Android - Create apps in Visual Studio / C# with Mono
Requesting Gravatar...
I am vb.net programmer , and looking for some thing to develop the the application for Android.
Left by Ahmad on Oct 29, 2011 4:43 AM

# re: Android - Create apps in Visual Studio / C# with Mono
Requesting Gravatar...
So, I need to pay $400/year to develop android in C#, is that it? Or the $400 are only for the monoDevelop?
Left by Diogo Costa on Feb 28, 2012 7:54 AM

# re: Android - Create apps in Visual Studio / C# with Mono
Requesting Gravatar...
$399 for the mono license gives you one year of upgrades as well... I suppose if you weren't worried about upgrades you could just consider it a one-time fee...
Left by Bill on Mar 08, 2012 10:12 AM

# re: Android - Create apps in Visual Studio / C# with Mono
Requesting Gravatar...
Java, C#, C++, shit! Android for VB.NET!!! :)
Left by Sr. R00t on Mar 21, 2012 9:07 PM

# re: Android - Create apps in Visual Studio / C# with Mono
Requesting Gravatar...
i have doubt in my application.if i buy licence ,we can easily deploy apk in mobile device
Left by karthik on Dec 13, 2012 12:20 PM

# re: Android - Create apps in Visual Studio / C# with Mono
Requesting Gravatar...
I am developing an own app with another SDK, Ozeki VoIP SIP SDK, and it will be a VoIP app (like this one: http://www.voip-sip-sdk.com/p_456-voip-android-integration-voip.html). It also requires knowledge in C# and Visual Studio.
Left by m.mosley on Mar 05, 2013 7:59 AM

# Android suing .net tutorial pdf
Requesting Gravatar...
Is there any mono-droid using c#.net (e-book )tutorial available in pdf form ?
Left by RITESH on Mar 30, 2013 11:01 PM

# re: Android - / C# with Mono tutorials
Requesting Gravatar...
i need tutorials and books for beginners
Left by Abdullahi Yusuf on Jun 28, 2014 4:46 AM

Your comment:
 (will show your gravatar)


Copyright © Bill Osuch | Powered by: GeeksWithBlogs.net