Getting started with Android

15 / Feb / 2011 by Partho Ghosh 3 comments

Hello world, this is my first blog ever. So, apologies for any kind of mistakes committed :p

Now lets get down with the actual business. Today I am going to talk about application development on Android platform. I am still a newbie on Android platform (a recent adapter in fact). I decided to write this blog so that other newbies like me can read it and after reading it can actually create more than a hello world application. Okay, so to start with we need to setup environment for Android application development. I am going to divide the whole blog into two sections, Setting up of Android SDK and development of a small application for Android. So, here we go:

  • Setting up Android SDK:Setting up Android is not at all a daunting task. developer.android.com provides a great documentation for setting up the Android. I am going to cover up the steps in as simple way as possible. For system requirements, refer System Requirements. So, here we go:-
        • Download the Android SDK (according to your preferred OS platform) from here( It is the initial tool and doesn’t actually help in development of application as it does not provide any android platform or third party tool- read the “readme” for further details) and unzip/untar it to a favorite safe location in your machine (Windows version has an exe also. On linux, make sure you are the owner of the directory in which the files are unzipped or untarred)
        • Now start up the Eclipse IDE (You can download it from here). Association between Eclipse and Android is just great. One can use other IDE(s) like IntelliJIDEA(if any other exist besides Idea and Eclipse, do let me know) or in fact can develop without any IDE if wants to. I prefer Eclipse as I feel comfortable with it and also Android application development integration is great. Okay, so now once you started Eclipse, you need to install the ADT (Android Development Tools) plugin to start up with the development. To install ADT, you can use Eclipse’s package manager (refer steps from here…note: when installing on Linux, if you run into dependencies can’t be resolved problems then you might need to install Google plugin from here)

        • Once you are through with installing ADT for Eclipse, you now have to add platforms and other components for application development. To add platforms and components, fire up your Eclipse IDE, select Windows>Android SDK and AVD manager (make sure path of Android SDK is set via preferences>Android option)>Available Packages >select the required platforms and components and hit install selected. Now sit back and relax till your downloads get completed. Once downloads are over, you are done with setting up the environment 🙂

  • Developing a small UI based application:

Okay, now since we have our IDE and Android development environment in place, we can dive

into the actual stuff, that is developing the application. I’ll be a creating a simple game called “Try your Luck” where the player will feed in a number between 1-9 and if he/she is lucky, he/she will get a cookie else the player is not lucky. So here are the steps:

        • To create a new project, select New>project… in Eclipse.
        • Select Android, android project and then fill in the project credentials like project name, application name, package name and activity (represents what the task the application is going to perform) name.

        • Once you are done with creating the project, the package explorer pane of the left of Eclipse window will be populated with project tree. Open the .java file situated in your package. In this application’s case, it is tryYourLuck.java.

          [java]
          package com.partho.tryYourLuck;
          import java.util.Random;
          import android.app.Activity;
          import android.os.Bundle;
          import android.view.View;
          import android.view.View.OnClickListener;
          import android.widget.Button;
          import android.widget.EditText;
          import android.widget.TextView;
          public class TryYourLuck extends Activity {
          /** Called when the activity is first created. */
          Button input;
          EditText value;
          TextView result;
          @Override
          public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          input = (Button)findViewById(R.id.input);
          value=(EditText)findViewById(R.id.TextField);
          result= (TextView)findViewById(R.id.output);
          int seed;
          Random rand= new Random();
          seed= Math.abs((rand.nextInt()%10)+1);
          input.setOnClickListener(new ValueChecker(seed,result,value));
          }
          }
          class ValueChecker implements OnClickListener
          {
          TextView result;
          String tempText;
          EditText value;
          ValueChecker(int s,TextView r, EditText v)
          {
          tempText=""+s;
          value=v;
          result=r;
          }
          public void onClick(View src){
          if(tempText.equals(value.getText().toString()))
          result.setText("You get a Cookie!Congratz… :)");
          else
          result.setText("Better Luck Next Time… :(");
          }
          }
          [/java]

        • In the above code, class tryYourLuck is a simple activity class which is going to perform some activity/task when the application is going to be invoked. onCreate() is just like main() of any Java program which acts as an entry point for the application. setContentView() sets the GUI of the Application. The savedInstanceState is a Bundle type object which can help you manipulate application’s state. Button, EditText, TextView are Android widgets which are used for user interaction. All of the above widgets are initialized after setContentView() with the help of ids provided in main.xml (The view layout). The setOnClickListener binds Button to onClickListener(Just like Java :))
        • Now a little bit info about the UI(User Interface design). Android separates UI designing from actual logic designing. You can hard code your UI or use the XML UI designing system of Android. I, in this project, modified the main.xml (which is found in res/layout inside your project folder) according to my need. Now here comes the beauty of Eclipse into play. Eclipse provides you this cool drag and drop UI designing feature where you can just drag and drop the various elements on screen (I think its due to GEF).
        • Now once you are through with writing code and designing the UI (or vice-versa :D), you can execute your application on virtual devices provided by the SDK. You can create your own Android Virtual Device(AVD) from window>Android SDK and AVD Manager>Virtual Devices>new. Once you are through with creating your AVD, you can just hit the run button or (ctrl+11) to run your application.

So, hope this small demo can help you get started working on Android. I myself is a newbie and there is lot to explore. Will come back with more in future. Ciao.

Regards,

Partho Ghosh

FOUND THIS USEFUL? SHARE IT

comments (3)

  1. Manoj

    Found this source of information good on android development which described in detail about how to start android development. Here is an another informative video tutorial on getting started with android development at, hope this will help developer. Apart from this mobile devs can surf this to look for quality content related to questions and answers on android development.

    Reply
  2. Arvind

    Hi Partho,great information .thank u.relatively new to android dev.not able to integrate android ADT in eclipse.can u help.gives error ”

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *