When it comes to mobile programming, Android is one of the vastly spread mobile OSes around, so how would you as a .NET programmer write android applications? It turns out there is a Monodroid project (currently in beta) which you can use to write android applications in C# and managed .NET environment and you can reuse your existing knowledge. Pretty cool, except it is a commercial framework once released. The alternative is to use freely available android tools and SDK, but the catch is that you need to be familiar with Java language instead of C#. But how different is that? Should it matter for a programmer at all? Let’s find out.

Java Language

For a C# programmer, the language should be very similar as they are more similar and different. There are some differences in Generics, Iterators, etc. but those are easy to master. Of course you don’t have C# 3.0 syntactic sugar luxuries in Java world. One thing that may seem odd for a .NET developer is the notion of inline classes which are non existing in .NET world. This construct allows you to specify an interface implementation inline, instead of creating a full blown class. This comes in handy for example, when you implement click listener interfaces on your class. Here’s an example:

1
2
3
4
5
6
7
8
9
public class MyActivity extends Activity {
protected void wireEventHandlers() {
this.mybutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
showMessage();
}
});
}
}

In above example, OnClickListener is actually an interface where implementation (merely a method) is implemented inline. A .NET developer also may write the above snippet as this, which of course does the same job:

1
2
3
4
5
6
7
8
9
10
11
public class MyActivity extends Activity 
implements View.OnClickListener {

protected void wireEventHandlers() {
this.mybutton.setOnClickListener(this);
}

public void onClick(View view) {
showMessage();
}
}

The C# goodies I missed when developing in Java were mostly delegates and inability to use them as functional blocks of code, and also the most argued var keyword.

Tools of the Trade

There are two choices when you start developing Android applications. What most people use is the Eclipse IDE which is one of the worst IDEs I have ever worked with. Eclipse allows development for different platforms and languages: C/C++, Java, PHP and now Android. The good thing about it is that it is free and has a lot of plugins but that’s about it.

It caused a lot of pain for me during the development and the IDE seems immature at best when compared with other IDEs or probably in your case, comparing to Visual Studio with all its bells and whistles.

Is there a better alternative? Fortunately, yes. Good guys at JetBrains have added Android development support to their Java IDE called IntelliJ Idea and if you have happened to use their Resharper plugin for Visual Studio, specially with IntelliJ Keyboard shortcuts, you’ll feel right at home. IntelliJ Idea has a Community Edition that is free and open-source.

Other than an IDE you need to get Android SDK and emulator. You can download the SDK manager from this google web page and once downloaded you need to download a specific version of SDK for the android platform you plan to develop your application on, from within the SDK Manager.

Now that you have an IDE and downloaded the necessary SDK you’re all set. In next post we’ll start to write a small app that works with a REST API so that we see how things are easily done and how a regular .NET developer is able to write full blown Android application in no time.