Pages

Tuesday, August 6, 2013

Understanding Android Project Structure (Eclipse)

In my previous post I showed you how to create a simple Hello World Android application. This post is about understanding the Android project structure with Eclipse.

As the Android project is also a simple JAVA project there is not much more difference between any standard JAVA project and Android project.

Android Project Structure
Android Project Structure
The above image shows the typical Android project structure in Eclipse IDE. Let's take a folder one by one.

assets/
This folder is empty. You can use it to store any raw files. All the files you save here are compiled into an .apk file as it is, and the original file name is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager.

gen/
This folder contains the all the JAVA files generated by ADT (Android Developer Tools), such as your R.java file, interfaces, etc.

res/
This folder contains Android application resources, such as layout files, drawable files, string values, etc.
  • colors/
    This folder is used to store XML files that describe colors.
  • drawable/
    This folder is meant for Bitmap files like PNG, JPEG, GIF and XLM files that describe any Drawable shapes or Drawable objects.
  • layout/
    All the XML files that are compiled into screen layouts and part for the Android application screen.
  • values/
    This folder stores all the XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.
  • menu/
    This folder is used to store the XML files that define application menus.
AndroidManifest.xml
Every Android application must have an AndroidManifest.xml file. The file name should not be change to any other name. Also the file should be in the root directory of your Android project. This file represents all the essential information about the Android application to the system. This information is used before the any of the application's code runs.

Thursday, August 1, 2013

Hello World Android

In my previous post I showed you how to setup a Android development environment. In this post I will show you writing your first Hello World Android application.

  1. Go to File Menu -> New -> Android Application Project.

    Drilling JAVA
    Hello World Android
  2. You will see the below screen once you click on the Android Application Project.

    Hello World Android
    Creating New Android Project

    The Application name and the project name can be differ as the project name is only used by the eclipse. But it should be unique in the workspace. Later on the application name will be used for creating the apk file. For example here the apk file will be created as HelloWorld.apk.

  3. Now it's time to configure the Android project. Here you can define the eclipse workspace location, Creating custom icon for you application, etc. 

    Drilling JAVA
    Configuring Android Project
  4. Now it's time to create your Android application icon. This icon will be displayed with the apk file as well as after installing the application as a short cut.

    Drilling JAVA
    Android Application Icon Creation
  5. After clicking on next you will see the below screen. This screen offers you to create the main activity where the application starts. It is a starting point of any android application.
    Android Activity Creation
    Create Android Activity
    Select blank activity for now. It will create a new blank activity, with an action bar and optional navigational elements such as tabs or horizontal swipe.
  6. Once you click on next after creating the blank activity, you will see the below screen. This screen is meant for defining a custom name for the main activity. By default it is MainActivity and layout name is main_activity.xml.
    Android Main Activity
    Configuring Android Main Activity
  7. On click of finish, the project will be created in the eclipse workspace.