Sunday, January 12, 2014

Building your first Hello World Android application using Eclipse

For Eclipse fans or users, who wants to use Eclipse IDE instead of JDeveloper IDE. All you have to do is to install Andoroid SDK, which will come shipped with Eclipse IDE.
For more information about installing SDK refer to the previous post

Creating your First HellowWorldApplciation

     1.  Refer to your SDK installation folder as shown in the following figure:

2.   Double click eclipse.exe icon to launch eclipse IDE.

   3.  Go to file menu item > new > Andoroid Application Project.

   4.  Fill the name of your new application as shown in the image below. For now, you need to fill the Application Name, other fields will be populated automatically, you can change according to your preferences, but for now keep the defaults. And click Next.

     5.  Click Next twice and keep the defaults, until you reach the activity name. Activities is the main building blocks of any Android application. Each mobile application consists of several activities that represented by a class that extends Activity class. Keep the defaults and click Finish.

6.  After you click finish the eclipse will generate the default required packages and classes to run your application.

From the figure below you can notice that a class with the name of your supplied activity; have been created. This class contains the methods related to life cycle of this activity.

Activity could be for example, displaying contacts list, showing calculator application screen, etc.

      7.  Another file to consider is activity_main.xml; this file is the layout file, that it is referenced by your application when building its interface. You would modify this file frequently to reflect your change in activity layout. This file resides res/layout directory.

    8.   The followings file is strings.xml file. From the figure below you can see that this file is located under res/values folder. This file contains all the texts that your application uses like buttons, texts, etc.

  9.   One more file you need to consider is the file, from the figure below, you can see that this file resides in gen/com.example.helloworldapplication package. It is an automatically generated file, and you should not modify it.
          This file acts as glue between activity java file like your and other resources like strings.xml file.

 Create Android Emulator
1.       Before you run your Application, you need configure you Android device Emulator. Click on windows item > Android Virtual Device Manager.

2.       The virtual device manager will be launched, click on New to create new Virtual device manager.

3.       The device manager will be launched, fill in the data as shown in the figure below. Click OK.

4.       Your new device now is created and ready to use.

5.       Select your device and click on start on start the virtual device.

6.       Now, your virtual device is started and ready to deploy your applications on. By finishing this step, your environment is ready to deploy your HelloWorldApplication.

Deploying your Application to the Emulator
Now, your environment is ready to deploy your applications, and starts accept user interactions and requests.

1.       To deploy your application, click on project menu item > Build All.

2..       This will create HelloWorld.apk file and load it to your Emulator.

3.       To run your application right click on the project and choose from context menu Run As > Android Application.

4.       After running your application, now you can access it and try it on Emulator. Use the Emulator as you use your mobile, you can find your deployed application in the list of applications as shown below.

5.       Click on HelloWorld icon to launch the application.

Congratulations, you have developed your first Android application using Eclipse IDE. In next posts I will provide another examples regarding Android Applications, if you have any note or question, please post it below.