Android for Mobile Apps

Android is a complete open source stack that allows one to build mobile applications. The stack includes an operating system, middle-ware and common applications. It also provides us with a Java API to develop our own custom mobile applications. It does not discriminate between common applications vs custom applications. Everything that the common applications can do so can yours (making calls, sending SMS, etc.).

What gets me excited is the (Linux kernel based) OS. There is no open source OS on the mobile platform. This is a major plus when it comes to mobile environments.

Before going into an Android sample, it is obvious to ask…what about Java ME (previously called J2ME). I do not see any reason why there cannot be a Java ME runtime created for Android OS. With that we could continue to use Java ME. Also this would open up use of JavaFX on this platform. As of today I could not locate Java ME implementations. If the reader knows of one please do let me know.

The one concern I had was regarding the Optional API’s in Android. It is a known fact that not all mobile devices are created equal (in hardware and other related device capabilities). Some devices will not support a certain feature therefore those API’s will not work on them. This is exactly the reason why Java ME created configuration and profiles. So now the Android optional API is going to end up in the same situation as Java ME. Whatever they decide to call it eventually, there has to be some basic API sets such as Java ME’s configuration and profile. So I do not see any big need to jump ship from Java ME to Android (other than the new car smell). I do believe that eventually there will be a Java ME implementation on the Android.

Cutting through the chase, lets build a quick hello world application and then move on to something bigger. An Android application consists of one or more of the following building blocks:

  • Activity – An activity is nothing but a user screen.
  • IntentReceiver – These are non UI components you build so that you can listen for external events such as a phone ring.
  • Service – Non-UI component that will always run in the background.
  • Content Provider – Allows the application to store data locally.

First get yourself a copy of Android from http://code.google.com/android/intro/installing.html. Follow the instructions there or just do the following:

  • Unzip the Android zip to some folder.
  • Add <android-folder>\tools to your OS path environment.
  • Install the Eclipse plugin via URL https://dl-ssl.google.com/android/eclipse/ . Restart Eclipse if prompted.
  • Open Eclipse Window->Preferences. Select Android on the left and set the SDL location to yours (example C:\mathew\android-sdk_m5-rc15_windows).

Now create a New Android project in eclipse. It will pop up

Click finish and you should now have your project ready. The wizard has created the following basic application class named HelloApplication.java

Lets modify this to

Right click on the project … select Run As -> Android Application. You should now see the Android emulator load up…


If all worked fine, you should now have a working development environment. Now lets dig a little deeper. In our HelloApplication class we built the UI using API’s directly in the java code. Android provides an alternative approach to define your UI screens in an XML meta language. Android comes with a slew of layout managers to lay out your UI components. Specific UI components are valled View’s and views can be grouped into ViewGroup’s. View groups can contain either views or groups.

Lets modify our program to use XML for defining our screens (like HTML).

We have removed the java code to create UI widgets. R.layout.main now refers to res\layout\main.xml. XML inside it is:

Running the application should now get you to the following output…