Friday, 14 November 2014

AndroidManifest.xml file in android

The AndroidManifest.xml file contains information about your package, including components of the application such as activities, services, broadcast receivers, content providers etc.
It performs some other tasks also:
  • It is responsible to protect the application to access any protected parts by providing the permissions.
  • It also declares the android api that the application is going to use.
  • It lists the instrumentation classes. The instrumentation classes provides profiling and other informations. These informations are removed just before the application is published etc.

This is the required xml file for all the android application and located inside the root directory.

A simple AndroidManifest.xml file looks like this:



Elements of the AndroidManifest.xml file

The elements used in the above xml file are described below.

<manifest>



manifest is the root element of the AndroidManifest.xml file. It has package attribute that describes the package name of the activity class.


<application>



application is the subelement of the manifest. It includes the namespace declaration. This element contains several subelements that declares the application component such as activity etc.


The commonly used attributes are of this element are iconlabeltheme etc.
android:icon represents the icon for all the android application components.
android:label works as the default label for all the application components.
android:theme represents a common theme for all the android activities.

<activity>


activity is the subelement of application and represents an activity that must be defined in the AndroidManifest.xml file. It has many attributes such as label, name, theme, launchMode etc.
android:label represents a label i.e. displayed on the screen.
android:name represents a name for the activity class. It is required attribute.

<intent-filter>


intent-filter is the sub-element of activity that describes the type of intent to which activity, service or broadcast receiver can respond to.

<action>


It adds an action for the intent-filter. The intent-filter must have at least one action element.

<category>


It adds a category name to an intent-filter.

Dalvik Virtual Machine

As we know the modern JVM is high performance and provides excellent memory management. But it need to be optimized for low-powered handheld devices.

The Dalvik Virtual Machine (DVM) is optimized for mobile devices. It optimizes the JVM for memorybattery life andperformance.

Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.

The Dex compiler converts the class files into the .dex files that run on the Dalvik VM.

Let's see the compiling and packaging process from the source file:




The javac tool compiles the java source file into the class file.

The dx tool takes all the class files of your application and generates a single .dex file. It is a platform-specific tool.

The Android Assets Packaging Tool (aapt) handles the packaging process.

Thursday, 13 November 2014

Android Project Structure

Any Android project contain things such as application source code and resource files. Some are generated for you by default, while others should be created if required. Lets have a look at android eclipse project directory structure below :


 Src :

           The src folder contains the Java source code files of your application organized into packages. You can have more than one package in your Android application. Its always a good practice to break the source code of your application into different packages based on its core functionality.  All the source files of your Activities, Services etc. Goes into this folder. In the above screen, you can see the source file of the Activity that we created for our project.


Gen :

         The files in the gen folder are automatically generated by the ADT. Here the R.java file contains reference/id's  to all the resources in the res we use in our program. Each time we add a new resource to the project, ADT will automatically regenerate the R.java file containing reference to the newly added resource. You should not edit the contents of R.java file manually or otherwise your application may not compile.


ANDROID <version number> :

              This folder is also called Android target library in Android project structure. The version number will be  same as the build target version that we choose while creating a new project. The android.jar file contains all the essential libraries required for our program.

ASSETS

             The assets folder is used to store raw asset files. You can keep any raw data in the assets folder and there’s an asset manager in Android to read the data stored in the folder. The raw data can be anything such as audio, video, images etc. On important point about assets folder is that the data stored in this folder can’t be referenced by an ID. To access a data in this folder, we have to work with bits and bytes.

BIN :

      Bin folder is where our compiled application files go. When we successfully compile an application, this folder will contain java class files, dex files which are executable under Dalvik virtual machine, apk archives etc.

RES :

         Res folder is where we store all our external resources for our applications such as images, layout XML files, strings, animations, audio files etc.

Sub folders:

res/drawable

This folder contains the bitmap file to be used in the program. There are three different folders to store drawables. They are drawable-ldpi, drawable-mdpi, drawable-hdpi. The folders are to provide alternative image resources to specific screen configurations. Ldpi, mdpi & hdpi stands for low density, medium density & high density screens respectively. The resources for each screen resolutions are stored in respective folders and the android system will choose it according to the pixel density of the device.

res/layout

XML files that defines the User Interface goes in this folder.

res/values

XML files that define simple values such as strings, arrays, integers, dimensions, colors, styles etc. are placed in this folder.

res/menu

XML files that define menus in your application goes in this folder.

ANDROID MANIFEST FILE :

          AndroidManifest.xml is one of the most important file in the Android project structure. It contains all the information about your application. When an application is launched, the first file the system seeks is the AndroidManifest file. It actually works as a road map of your application, for the system.

              The Android Manifest file contains information about:

                               Components of your application such as Activities, services etc.
                               User permissions required
                               Minimum level of Android API required

IC_LAUNCHER-WEB.PNG :

             This is an icon to be used in Google play. Applications on Google Play require a high fidelity version of the application icon. It is not used in your actual app or the launcher, so it is not packaged in the APK.. The specifications for the high-resolution icon are:
32-bit PNG with an alpha channel
512 x 512 pixels
Maximum size of 1024KB

PROGUARD-PROJECT.TXT :

            Everything in the proguard-project.txt file will be in commented out state, because in general most people don't have any project specific needs, just to run ProGuard tool with standard settings.
The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer.

PROJECT.PROPERTIES :

             Project.properties is the main project’s properties file containing information such as the build platform target and the library dependencies has been renamed from default.properties in older SDK versions. This file is integral to the project.


Creating Simple Android Application

Creating Android Application 


1.Click on eclipse icon.

2.To create  android application goto File->New->Android Application.

3.Fill the Details in this dialog box and click finish.


4.Now an android project have been created. You can explore the android project and see the simple program, it looks like



5.Run the android application

              To run the android application:
              Right click on your project > Run As.. > Android Application  

Wednesday, 12 November 2014

Android Installation Procedure


Android Installation Procedure :


Android supports java, c++, c# etc. language to develop android applications. Java is the officially supported language for android. All the android examples of this site is developed using Java language and Eclipse IDE.

Here, we are going to tell you, the required softwares to develop android applications using Eclipse IDE.

Supported Operating Systems:

Windows
Mac
Linux


Required Softwares:



1. JDK (1.5 or later) 

        'download from here:http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. ADT Bundle 

      download from here:http://developer.android.com/sdk/index.html

Installation Procedure:

1.Install JDK

2.Unzip ADT Bundle inside you will find two folders called eclipse,sdk.

3.do not separate eclipse and sdk from ADT bundle folder.

4.open eclipse folder and you will find eclipse application file just run that file it is going to open eclipse IDE after you can start android application development.

5.Create an Android Virtual Device (AVD).
          
           For running the android application in the Android Emulator, you need to create and AVD. 
           For creating the AVD:                       

                  1.Select the Window menu > AVD Manager.
                  2 .Click on the new button, to create the AVD.
                  3.Now a dialog appears, write the AVD name e.g. myavd. Now choose the target android                         version e.g. android4.0.
                 4.click the create AVD.


6.Install Tools and Extras folder in Android SDK Manager.

                1. Select the Window Android SDK Manager.
                2.Select tools and extras check box.    
                3.Click install packages.