Tuesday, 4 June 2013

How To Create Your First Android Application!

Ah well, I know this is late but Android still has that charm and it's getting bigger and better, I actually wanted to start off with 'Building an Android App in Unity', but as the stats say not many have used unity(relative), so I thought I would write a post on this first and then move onto the 'unity' thing.

So this is going to be one informative post and a post which is going to raise that learning curve steeply.

Right, so the pre-requirements that you are supposed to have are listed below along with their downlaod links:

1. A Java Development Kit - You can download the specific JDK for your system from http://java.sun.com/javase/downloads/index.jsp

2. The Eclipse - You can get this from http://www.eclipse.org/downloads/  "Classic" is recommended, however not mandatory though.

3. Android SDK Tools - This can be found at http://developer.android.com/sdk/index.html . I would recommend you to install this in the 'C' drive, and again not mandatory (for people who want to stand out from the rest :P)

4. Finally, the Android Developer Tools (ADT)—Eclipse Plugin, which of course need to be installed from inside the Eclipse.

  • Open Eclipse, go to Help menu, click on Install New Software, then select Add.
  • Now you will see a Dialog Box, in the dialog box, enter ADT Plugin for the Name and https://dl-ssl.google.com/android/eclipse/  in Location; then press OK.
  • From the various things you see next, select Developer Tools and click Next, and Next again after the installation of the developer tools is completed.
  • Further, read the terms of license agreements, if you really want to, if not, just click on I agree, as you do most of the times, or perhaps all the time, and then click Finish.
  • Now let the installation complete and once it is done, restart Eclipse.

Right, now go to Window menu and select Preferences.

Select Android, and then for the SDK Location, browse to where you installed the Android SDK Tools, and select that. Click Apply, then press OK.
(Tired already? Then this ain't for you. Close this page and go get some sleep.

Oye wait wait. Come on, don't be a loser. Complete the thing which you've started. Be a MAN man!)

Next, you need to install the SDK components. This is done using the Android SDK Manager which is apparently found under the Window menu in Eclipse (If not launch it from the folder which contains the SDK manager). Launch the manager and select Documentation, SDK Platform Android 4.2.2, and Samples for SDK API 17; click Install 3 packages(These are the latest versions, of course may not be the latest when you read/follow this post.)

Ah finally this 'downloading' and 'installing' thing is done (I know i sucked big time, but can't help you know :/)
So, now we will turn to a somewhat interesting thing which is creating a Virtual Android Device which apparently is also known to be an Android Emulator. 
The Andorid website defines the AVD as an emulator configuration that lets you model an actual device by defining hardware and software options to be emulated by the Android Emulator. (Not the greatest of definitions to be honest, but I guess we have to bear with them for that.)

Right so, the easiest way to create an AVD is to use the graphical AVD Manager, which you launch from Eclipse by clicking Window > AVD Manager. You can also start the AVD Manager from the command line by calling the android tool with the avd options, from the <sdk>/tools/ directory.

I will break it to make it more clear adn also the image below will clear off all your doubts, if any
To create an AVD, select Window AVD Manager, and click New. Give the device a Name and select the Target SDK from the drop-down and also the Device
The rest we will keep as they are, since we aren't interested in those at this point in time.

Now, you have a virtual android device, which can be started by simply clicking on the Start button and then of course Launching the AVD, after which you 'll see something like this:

How to Create a Project!
Right so this is perhaps the most interesting part in this post. Let the Emulator run, and we will restart the Eclipse so as to create our First Android project.
To do this go to  File -> New -> Other -> Android and select Android Project.
Type in your Application name, Project name and click Next and Next again untl you get to Finish and click it once you get there (leave all the options as default, no modification required)

You should see something like this once the Activity has been loaded

Now if you're interested in knowing some concepts used in the Android App Development, read the points below:

Activity (MainActivity.java): is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows. The onCreate method is called when the Activity is being created with the intention of being the current running Activity.
Perhaps you might want to check this out Activity

Manifest (AndroidManifest.xml): Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code.
More info Manifest

Intent: An Intent is exactly what it describes. It's an "intention" to do an action.
An Intent is basically a message to say you did or want something to happen. Depending on the intent, apps or the OS might be listening for it and will react accordingly.
Think of it as a blast email to a bunch of friends, in which you tell your friend John to do something. The other folks will ignore the email, but John will react to it.
To listen for an intent (like the phone ringing, or an SMS is received), you implement a broadcast receiver.
If you want to fire off an intent to do something, like pop up the dialer, you fire off an intent saying you will.
More info Intents

How to Run and Debug!
The answer to this thing is pretty simple,  Select the project in Eclipse, and from the Run menu, select Run; then select Android Application and OK in the dialog.

It will take some time for the app to get installed and finally on the AVD you'll be able to see something like this:

And just like this we have made our very first Andorid App.
Thank you for your patience, hope you've enjoyed the learning ride. Happy Androiding, adn do share this if you managed to learn something from this post.


  1. Nice and detailed post. Funny too :P Thnks man!

    1. YOu're welcome. Glad you liked it and enjoyed it :D

  2. awesome post man, very helpful!

    1. thanks for the visit man.. check out my other posts as well..