Print Shortlink

Dive into Android development – II

We had Eclipse IDE with Android plugins configured in the earlier post. Let’s start with our traditional hello world example. The application should pop up a Hello World dialog box.
Let’s create a simple Android project in Eclipse, call it ‘DiveIntoAndroid2‘. Eclipse will ask for a target platform and we’ll choose ‘Android 2.2’. You will have to specify a root package name for the project and let that be ‘com.durasoft’. Clicking finish button will give you a project structure as shown below.
You will write the code in the DiveIntoAndroid2Activity.java file. An Activity in Android is equivalent to a window with all the UI components in it. So typically an Android application is nothing but a collection of activities and DiveIntoAndroid2Activity is one such activity which will be launched when you execute the application.
Let’s create a dialog box with the message “Hello World”.  There are a number of ways to implement this, but let’s take the simplest route. 
      AlertDialog.Builder alertDlgBuilder = new AlertDialog.Builder(this);
        AlertDialog alertDlg = alertDlgBuilder.create();
        alertDlg.setMessage(“Hello World”);
        alertDlg.show();

If you have worked with Java Swing or AWT or WinForms working with UI components in Android will be a breeze. Let’s not add more code this time and we’ll just focus on executing it.
Execute the application by right clicking the project in project explorer and selecting ‘Run As’ Android application. The application will automatically launch the Android emulator that we had already created during the setup. 
The emulator will be launched and will take time to start and initialize, similar to starting a mobile device as shown below.
After you unlock by dragging the lock bar to the right side, the application get’s launched and you get the output as shown below.
I had created an AVD called ‘Froyo’,  targeting the Android 2.2 platform and had selected it as default. So when I ran the application Froyo got launched.
Btw what is Froyo?

    

Leave a Reply