Wickasitha's tech Blog

blogging everything

Android applications in C# using Visual Studio

I recently got an Android mobile development project and was really interested in writing the application. After downloading the Android SDK as well as the 32-bit Java SDK I got it all installed and running the sample apps with Eclipse and browsed around the code.

Firstly, I wasn’t really too keen on getting into another development environment. Secondly, I really didn’t want to do any Java development if I didn’t have to. C# is my happy place, C++ is for the ugly stuff if you need it, Java is just, well, ugly… Besides the last time I did any serious Java was in previous workplace , enter MonoDroid to save the day!

Getting Started

To get everything installed read this guide. Then you can read about the API and architecture to get a better understanding about how it all gels together. Pretty much everything you need including signing up for the newsletter can be found by going directly to www.monodroid.net.

Once you have everything installed it’s pretty easy to get going. The beauty about diving in using a language you are familiar with, means you can get used to the Android SDK without having any knowledge of Java or even C++ (for more advanced features). MonoDroid wraps up all the calls using standard .NET constructs through a JNI bridge, plus, you get all of the power of the standard .NET API’s which work in Linux/Android.

Hello Android

Following the tradition of “Hello World”, let’s jump right in and write an Android application.

  1. Make sure that you have everything installed, this guide couldn’t have made it easier. 

  2. Create a new Project in Visual Studio: New MonoDroid project in Visual Studio 2010 

  3. MonoDroid does most of the heavy lifting for you. If you’re familiar with Android projects in Eclipse you should have any problems with the structure. Android uses layout and string resource files (the right way) for the UI. Activities are like UI controllers, all the info you need is on the Android Developers website

  4. Just run the application to check everything is working correctly, if you don’t have a device attached or an emulator running then now is the time to create one: Select a device to connect the debugger  

    If you don’t see anything then just click “Start emulator image”: Select an emulator to start or create a new one 
    Once again MonoDroid holds your hand by signing the package and also installing the Mono runtime if it’s not already available. 
    WARNING: If you are running an emulator then this will take a while, if you have a monster PC that does it in seconds then I hate you. 

  5. Unlock the phone/emulator and click the button: The default Hello World application  
    That’s it! There is a lot of documentation on writing Android applications. Java isn’t that far off in syntax to C# so it will be easy to pick up sample code all over the place.

Download sample code

More Information

The best place to start is the MonoDroid API design documentation. Do yourself a favour and browse the classes in the Android namespace. Make sure you check Android.Provider which gives you access to things like Contacts, Settings, Calls Logs etc. through static classes.

This Justin guy slicked the domain www.mono-droid.com in July 2010 already so this isn’t new, just widely available now and free for the time being. There is a lot of useful information on installing and developing here. He’s got videos too, everyone loves videos.


3 Comments


Leave a reply


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

RSS Feeds

QR Code

qr code

QR code created by QR code Widget

Fun with .NET

Visitors

Your Ads Here
Promote your products