14-Jul-11 (Created: 14-Jul-11) | More in 'Android 1.5'

How I have learned Android SDK: An Authors note

This is a draft. There may be all kinds of typos. So please treat the document accordingly. Thanks. Satya.

Perhaps there is more than one reason why one stumbles into a need to learn Android. Be those reasons as may.

Pre-Requisites

So you want advice.

Let's start at the prerequisites. Let's list them concretely.


Java
Eclipse

You need to be pretty good with the java programming language. Android SDK uses lot of new features of the java programming language especially Java generics. You may not need these on day one. You may want to brush up so that you are not surprised by the syntax of generics when you run into one.

You do need to know Java. Just the core language and its core libraries. You don't need to know server side java such as say servlets or a million other frameworks that are available on the server side. You do not need to know more sophisticated java frameworks such as Spring or Hibernate or any thing of that ilk. Just the core programming language.

what if I am not a java programmer??

Well, what can I say not everyone is perfect. No, I am just kidding. C# is pretty close. It is a bit of a jump if you know just "C". Any "C" based object oriented language will be pretty close Java.

At the core Android SDK is a UI framework like Swing or MFC

Although you don't need to know, if you are a Jock at writing desktop programs it will expedite your learning of Android SDK pretty quick. Because at its heart Android SDK is a pretty modern UI framework.

with the prevalance of server side web programming in the last decade these UI toolkit skills are a bit rusty in the industry if I were to take me as an example.

There is a small exception to this if you use something like Adobe AIR or Titanium from Appcelerator. These tools let you use web technologies and frameworks to do desktop like programming on Android. This trend has lot of potential but is not widely adapted yet.

So, when I started my skills are a bit rusty with desktop programming. So although benefecial, lack of it wasn't a big drawback to learn Android SDK.

what about eclipse

I strongly recommend so so so much that you spend sometime downloading and learning eclipse. This is the essential tool for ALL programming these days. I even use it as a file browser to operate servers and my local drives.

I have some links on my site and two basic articles that will help you work with eclipse for Java based projects. Android projects are essentially java projects in eclipse.

So LEARN it.

It will probably take a week for you to get used to it and my two articles are especially geared towards a crash course in eclipse for Java.

Good Luck there.

So that wraps up the pre-requisites.

In my case I knew both pretty well.

what is not a prerequisite

If you have never done mobile programming you may not know. But almost all mobile development efforts don't need a real device. You can do with just an emulator. This is true of android as well.

So the obstacles to get started with Android are minimal. What else:


Java is free.
Eclipse is free.
Android SDK is free.

Getting started

So I have downloaded and installed.

If you are inside a firewall of a corporation this is a painful experience. If you are on the open internet it gets considerably easier.

Even then, and after three years the android sdk installation process is unnecessarily sophisticated and keeps changing.

Expect to spend a day or two to get set up. (Ofcourse as a plug our book should help. I also have installation notes on my site which I keep updating every time I attempt an install)

Understand these first

I believe in a simple hello world to get started. A simple example like this will introduce to the following concepts


Activity (Equivalent to a window)
Resource files (Your layouts and ui objects as xml)
Generated R.java (constants for the objects above)
AndroidManifest.xml (config file for your app)
Creating a project in eclipse
Running the emulator 
Testing your project in the emulator

Once you understand these I strongly recommend that you understand the following in depth


Resources
Intents
Content Providers

The goal is not to pay lot of attention to source code and examples but to understand the concepts. This took me weeks as all three are either new or dealt very differentl in Android.

I call this the initial set. Understand these.

The second leg of your learning: Second round

Once you get the concepts basic concepts above it is time to venture into a play.

In this round you will exercise the following


Log.d (for debugging)
Menus
Controls
   Text
   Buttons
   layouts

Ofcourse being in eclipse you can always put break points to go through your code. However Log.d comes quite handy to send out strings to your debug console. You will need to learn how to enable to see these log messages.

Menus are very simple in android. You can use menus to test your ideas. In this round you can put various controls in your layout xml file and see them displayed on your activity.

Creating the layout file is somewhat similar to creating an html file. You have xml nodes for various controls including the layouts. One difference indeed is layouts. HTML do not have explicit layout nodes.

Learngng layouts is an intermediate skill. You can get along with simple layouts first.

Creating pleasing layouts is an advanced skill.

Once you have the controls in your layout files you can write java code in the activity class to orchestrate or manipulate and respond to those controls.

So menus and controls will give you a nice second round learning experience.

Round 3: Understand Activity Life Cycle

The first two rounds would have given your feet wet and comfortable with an android activity and put a few controls on it and make them do something.

Now you need to understand a crucial aspect of an activity. If you rotate your device (you can do this in the emulator) Android restarts an activity (not the application but just the activity component).

So you will need to understand how an activity behaves as you open your application rotate your device navigate into and away from your activity as activity gets partially and fully hidden how an activity gets destroyed etc.

So read up on the activity life cycle.

write a couple of samples to see what happens to the state of controls as you rotate the device.

Round 4: next up are components

You will learn in this round that Android uses a component model like windows COM+. You will understand its set of components and how threading works. Especially the behavior of the main thread.

In short you will need to know


The list of components
   Activity
   Service
   Receiver
   Content provider
The role of main thread
ANR: Android not responding message
Handlers
Loopers
Threads

In this round you will need to know the process and threading model used by various components in Android.

This will help you to write code that behaves well. You will know how to do long running work.

Round 5: Understand a service

Here you will know how to kick off various background work items on services. For example you can use menu items to start work on a number of services.

Learn here the limitation of a service running on the main thread. Understand how to run a service using a worker thread for a longer time.

Understand and learn the following:


Async service 
IntentService
WakefulIntentService
Progress Dialog

Understand the idea of how wakelocks play a role in services.

Round 6: BroadCast Receivers

You will need to know the following


Broadcast receiver
Invoking a long running service from a broadcast receiver
Understand wake locks
Understand notifications from broadcast receivers

Round 7: Dealing with device rotation

One of the hardest things to understand and code well is to understand what happens when a device gets rotated. How do you code so that your application behaves well and intuitively under these conditions is documented well and needs to be understood.

Round 8: Fragments and Fragment Dialogs

To deal with device rotation and variation Android introduced a new concept called fragments. At this point of your learning you should be able to grasp the importance and use of fragments.

Round 9: write a nice application that you can sell

At this point you have everything you need to write a stand alone application that behaves nicely, that looks nice, and saves its state in the database using content providers.

where to go next

The rest of learning is up to you. so far what we have learned and documented in the book include


OpenGL
Animation
Widgets
Media
Http Services and server side connectivity
Search API
Contacts API
Sensors
Drag and Drop
Advanced Controls

All these ideas are mostly stand alone. You can pick and choose what you want to learn at this point.