Thursday, October 3, 2013

Building Your First Android Application


Create a project with Eclipse





        Hope you have installed android SDK, now its time to start your own android application. So, it's important that you follow each steps...

1. Click File in the toolbar.
    File  à  New  à Android Application Project




2. Fill the window that appears as,
    
   
                                                                                                                                           

Application Name is the app name that appears to users. For this project, use "MyFirstApp".

Project Name is the name of your project directory and the name visible in Eclipse.

Package Name is the package namespace for your app (following the same rules as packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. For this project, you can use something like "com.example.myfirstapp."

Minimum Required SDK is the lowest version of Android that your app supports, indicated using the API Level.

Target SDK indicates the highest version of Android (also using the API Level) with which you have tested with your application.

Compile With is the platform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK.

Theme specifies the Android UI style to apply for your app. You can leave this alone.   
     
     Click Next


     3. On the next screen to configure the project, leave the default selections and click Next.


      
     4. The next screen can help to create a Launcher Icon.     



    5. Now you can select an activity template from which to begin building your app.  
        For this project, select Blank Activity and click Next.


    
    6. Leave all the details for the activity in their default state and click Finish.


    Your Android project is now set up with some default files and you're ready to begin building the app.



    7. Run as,



Anatomy of an Android Application


Now that you have created your first Android application, it is time to dissect the innards of the Android project and examine all the parts that make everything work. 
First, note the various files that make up an Android project in the 
Package Explorer in Eclipse 


The various folders and their files are as follows:

1. src — Contains the .java source files for your project. In this example, there is one file, MainActivity.java. The MainActivity.java file is the source file for your activity. You will write the code for your application in this file. 

2. gen — Contains the R.java file, a compiler-generated file 
that references all the resources found in your project. 
You should not modify this file.

3. bin  This folder contains the Android package files .apk built by ADT during the build process and everything else needed to run an android application.

4. res/drawable-hdpi  This is a directory for drawable objects that are designed for high density screens.
drawable-ldpi/mdpi/xhdpi are for other resolutions like low/medium/xlarge density screens.

5. res/layout — This is a directory for files that define your app's interface.

6. res/values This is a directory for other various XML files that contain a collection of resources, such as string and colors definitions.

7. AndroidManifest.xml — This is the manifest file for your Android application. Here you specify the permissions needed by your application, as well as other features (such as intent-filters, receivers, etc.). 

assets — This folder contains all the assets used by your application, such as HTML, text files, databases, etc.
res — This folder contains all the resources used in your application. It also contains a few other subfolders: drawable-<resolution>, layout and values, which can support devices with different screen resolutions and densities.


Observe the content of the AndroidManifest.xml file: 

<?xml​version="1.0"encoding="utf-8"?>
<manifest​xmlns:android="http://schemas.android.com/apk/res/android"
​​​​​​package="com.example.myfirstapp"
​​​​​​android:versionCode="1"
​​​​​​android:versionName="1.0">
​​​​<application​android:icon="@drawable/icon"​android:label="@string/app_name">
​​​​​​​​<activity​android:name=".MainActivity"
​​​​​​​​​​​​​​​​​​android:label="@string/app_name">
​​​​​​​​​​​​<intent-filter>
​​​​​​​​​​​​​​​​<action​android:name="android.intent.action.MAIN"​/>
​​​​​​​​​​​​​​​​<category​android:name="android.intent.category.LAUNCHER​"/>
​​​​​​​​​​​​</intent-filter>
​​​​​​​​</activity>
​​​​</application>
​​​​<uses-sdk​android:minSdkVersion="9"​/>
</manifest>


The AndroidManifest.xml file contains detailed information about the application:

➤ It defines the package name of the application as com.example.myfirstapp.
➤ The version code of the application is 1. This value is used to identify the version number of your application. It can be used to programmatically determine whether an application needs 
to be upgraded.
➤ The version name of the application is 1.0. This string value is mainly used for display to the user. You should use the format: <major>.<minor>.<point> for this value.
➤ The application uses the image named icon.png located in the drawable folder.
➤ The name of this application is the string named app_name defined in the strings.xml file.
➤ There is one activity in the application represented by the MainActivity.java file. The label displayed for this activity is the same as the application name. 
➤ Within the definition for this activity, there is an element named 

<intent-filter>The action for the intent filter is named  android.intent.action.MAIN to indicate that this activity serves as the entry point for the application.

 The category for the intent-filter is named android.intent.category.LAUNCHER 
to indicate that the application can be launched from the device’s Launcher icon. 

Finally, the android:minSdkVersion attribute of the <uses-sdk> element specifies the minimum version of the OS on which the application will run. 


As you add more files and folders to your project, Eclipse will automatically generate the content of R.java, which at the moment contains the following:


package​ com.example.myfirstapp;

public​ final​ class​ R​{
​​​​public​ static​ final ​class​ attr​{
​​​​}
​​​​public​ static ​final​ class​ drawable​{
​​​​​​​​public​ static​ final​ int​ icon=0x7f020000;
​​​​}
​​​​public ​static​ final​ class​ layout​{
​​​​​​​​public​ static ​final​ int​ main=0x7f030000;
​​​​}
​​​​public​ static ​final​ class ​string​{
​​​​​​​​public ​static​ final​ int​ app_name=0x7f040001;
​​​​​​​​public​ static ​final​ int ​hello=0x7f040000;
​​​​}
}


Note:
You are not supposed to modify the content of the R.java ​file; Eclipse automatically generates the content for you when you modify your project. 




Thank You.






    

0 comments:

Post a Comment

    Blogger news

    MIND MEDIA INNOVATIONS PVT LTD
    25/2953(2), Old GPO Building,
    Near Ayurveda College,
    Kunnumpuram,
    Thiruvananthapuram-695001
    Phone: +91 471 257 1001

    Email us @ :
    mindmediateam@gmail.com

    Total Pageviews

    Share us

    Cool Social Media Sharing Touch Me Widget by Blogger Widgets

    About

    Our hands with you, towards Android Technology