Wednesday, December 14, 2011

How to create Android Application?


The Android SDK provides the tools and APIs necessary to develop applications on the Android platform using the Java programming language. To start with Android application development, the developer needs to have elementary knowledge of Java and XML.
Well, starting with the creation of first android application,
a)    Select Eclipse->File->New->Android Project, in the dialog, fill the fields, Project Name (ex: MyFirstApp), Build  Target (to compile the application by a particular Android SDK), Application Name (name of application, ex:      MyFirstApp), Package Name (ex: com.myapp), Create Activity (ex: MyFirstActivity)
   b)       Click on Next->Finish. An android project folder with
           Name ‘MyFirstApp’ will get built in the left pane (Project Explorer) of Eclipse.
   c)       On exploring the Project folder, you will be able to see the sub folders /src, /gen, /res & AndroidManifest.xml as shown in the below image at positions 1, 2, 4 and 6 respectively.




There are four building blocks to build an Android Application- Activity file, R.java, Resource files and Android Manifest file as shown in above image at positions 1, 3, 4, 6 respectively. Activity files are used to write the Business logic of action happening on the Android Screen. The resource files are used to create the layouts for the screen. The Android Manifest file presents the essential information about the application to the Android OS, like- version, icon, activities and permissions given to application, which Android requires before running any application. R.java file does the mapping between layout files and Activity file.


Activity File

  • Edit MyFirstActivity.java in the package com.myapp (at position 1) as the code shown in the above image.
  • Next, the Emulator is required to see the output screen. Following are the steps to create emulator:
  • Select Eclipse->Window->Android SDK and AVD Manager. In the available dialog, select Virtual devices >New.
  • In the available dialog, enter the name of emulator (ex: MyDevice) and select the target API (Android version)for the emulator. Now click on Create AVD button.
  • The emulator with name ‘MyDevice’ will be added in the list of existing emulators (if any) on the previous dialog and to start the emulator select Start from the dialog.
  • To run the application, select Eclipse->Run->Run Configurations.
  • In the available dialog click on Run and see the log in the console window of the Eclipse.
The eclipse itself installs the application on the Android Emulator and the output can be seen in the Android Emulator as shown in the below image.
Output screen on Android Emulator


2 comments:

  1. I write the same code but i didn't get android development primer on the screen....

    ReplyDelete
    Replies
    1. Are you getting any error in Logcat?? Please post your activity code..!!

      Delete