Android - The Structure of an Android Project


The Structure of an Android Project 


After you create a new project in eclipse, you will see the following top-level folders in your package explorer.
                                                                      Figure 1-2


Each of them in detail:

  • /src : This folder will contain the java source files. In the screenshot(figure 1-3) you can see 'activity' file created in a sample project. The files in this folder will be organized according to the package.
                                                                      Figure 1-3
  • /gen : This is also a source folder, but will be contain Java source files that will be automatically generated by the android platform. Notable among the generated Java files is the R class, which you see in the screenshot. The framework will generate R class file and you can read more about it in the android documentation.
                                                                      Figure 1-4

  • /res : This directory contains all the external resources (images, data files etc) that are used by the android application. These external resources (content) will be referenced in the android application.This contains the following sub-folders

  1. /res/drawable
  2. /res/layout
  3. /res/values
                                                                     Figure 1-5

      1. /res/drawable : This folder contains all images, pictures etc. If you want to include an                                                                                     image or an icon in your android application, then you will be placing it in this folder.
       2. /res/layout : This folder contains the UI layouts that will be used in the project. These UI layouts are stored as XML files. You can read more about the UI layouts in the android documentation.
      3. /res/values : This folder again contains XML files, which contain key values pairs that will be referenced in the application. These XML files declare Arrays, colors, dimensions, strings etc. The main idea of having these values in a separate XML file is that the values can be used based on the locale without actually changing the source code. For example the messages in the application can be in different languages based on the use locale.
      4. /assets : This folder also contains external resources used in the application like the /res folder. But the main difference is that the resources are stored in raw format and can be read only programmatically.
  • Android Manifest File : An Android application is described the file "AndroidManifest.xml". This file will declare all activities, services, broadcast receivers and content provider of the application. It will also contain the required permissions for the application. For example if the application requires network access it must be specified here. "AndroidManifest.xml" can be thought as the deployment descriptor for an Android application.
                                                                                    Figure 1-6
    The "package" attribute defines the base package for the following Java elements. It is also unique as the Android Marketplace only allows application for a specfic package once. Therefore a good habit is to use your reverse domain name as a package to avoid collisions with other developers.
    "android:versionName" and "android:versionCode" specify the version of your application. "versionName" is what the user sees and can be any string. "versionCode" must be an integer and the Android Market uses this to determine if you provided a newer version to trigger the update on devices which have your application installed. You typically start with "1" and increase this value by one if you roll-out a new version of your application.
    "activity" defines an activity in this example pointing to the class "CelFahConverterActivity". For this class an intent filter is registered which defines that this activity is started once the application starts (action android:name="android.intent.action.MAIN"). The category definition (category android:name="android.intent.category.LAUNCHER" ) defines that this application is added to the application directory on the Android device. The @ values refer to resource files which contain the actual values. This makes it easy to provide different resources, e.g. strings, colors, icons, for different devices and makes it easy to translate applications.
    The "uses-sdk" part of the "AndroidManifest.xml" defines the minimal SDK version your application is valid for. This will prevent your application being installed on devices with older SDK versions.

Comments

Popular posts from this blog

EJB - Stateful vs Stateless

Inversion of Control vs Dependency Injection