Pages

Friday, 8 April 2011

First Steps (2) Android Building Blocks

As a developer with a long background in Microsoft technologies (VB then .NET and C#) moving to Android Java development was initially a bit of a challenge. Not least because I was required to stray from the comforts of my Visual Studio environment.

Having already traversed (or perhaps transcended?!) the bridge I thought I would impart some knowledge that may make the transition easier for others.

Building Blocks

When first creating an app you have to deal with Activities. These are essentially blocks of code that deal with user interaction. Coming from a Windows background it is easy to think of these as your Forms.

The interaction between activities are dealt with by Intents. These are a request for a type of action (start a new activity, launch camera, start an SMS, etc) and can also contain a Bundle which in WinForms terms would be your argument array.

Figure 1: Android Activity and Intent usage
Foundation Block

The thing that binds your project together is the manifest file which resides in the project root and is named AndroidManifest.xml. This defines the requirements, components and permissions of your app.You can think of this as your .NET app/web.config. I will being covering this in details as well as the overall project structure in a separate post.

To Conclude

Once you understand these key terms you have a good starting point for approaching your first "Hello World" project. With the aim of keeping my posts concise I will tie it up there, but please continue to follow the series.

First Steps (2) .NET Developer Moving to Android

This post has been renamed and moved to Android Building Blocks.

Thursday, 7 April 2011

First Steps (1) Welcome to Android Elements

Hello and Welcome to Android Elements. The aim of this blog is to assist those who are new to Android development, having already trodden the path myself. Posts will provide concise information and examples whilst pointing out potential pitfalls and problems.

It is now about 6 months since I first decided to have a stab at putting an Android app together after having my HTC Desire for a while. I am a professional developer but mainly on the Microsoft / .NET platform. Even so, the transition to Android, Java and Eclipse was not a smooth one...

Developing for Android

The initial hurdle was the general lack of good information and examples. Google have done an excellent job with their Android Developers site which will probably always be your first stop for information. But it for what is has in detail it lacks in examples.

Also, the nature of mobile development, particularly on the array of Android devices is complicated. Your web development skills will not help you here. Well maybe a tiny bit, but I wanted to sound dramatic.

I would also advise that you should be at the very least familiar with OOP and real-world programming methodologies if you want to start creating apps. This is not BASIC on your BBC Micro (showing my age there). If you're a seasoned Java developer who uses Eclipse on a Linux platform every day, then you have a huge advantage.


The Environment

Your choices for the IDE are the Eclipse or IntelliJ IDEA. Eclipse is by far the more widely used of the two and is also the one used in the Google guides, so this was my choice. However I have heard good things about IntelliJ so intend to check it out soon. I plan to do a whole post on setting up the environment later as there were some steps that I had trouble with even when following the Installing the SDK guide.

The Challenges

The Android platform is evolving rapidly and many of its strengths are also a headache for developers. Take the number of devices for example, great for Android, horrible for testing. Platform updates are also relatively regular with new features being added and old deprecated perhaps twice a year.

When you hit a problem and start searching you will often find examples using different approaches and sometimes raise more questions than answers; should you use the native Android methods?  Are they supported in all versions? Will the Java libraries do a better job? Or perhaps I need a third party library?
You can find a code example that is only year old but is completely out of date. 'Official' examples and best practices often do not exist. For the same reasons a good book only has a very short lifespan. This is very different from the .NET world.

Resources

It seems there are very few decent Android resources on the web. The most reliable have proven to be:
  • Google Developers - First stop for detailed information on objects and classes.
  • StackOverflow - A fantastic resource when you get stuck. Growing and helpful community, but be sure to search before you ask questions.
  • O'Reilly Programming Android - online book which is available for until it goes into publication. It's O'Reilly so expect content of the highest quality.

To keep ahead in the dynamic mobile environment you'll need to keep abreast of changes so you should follow (RSS or Twitter) some or all of the following:


Now it's time to take your first steps. Good luck...