Showing posts with label Android-HelloWorld. Show all posts
Showing posts with label Android-HelloWorld. Show all posts

Sunday, 26 October 2014

Hello World in Android more details


This tutorial explains provides you some basic explanation about the Android application project.

Following are the list of items which needs to be known when creating a simple application.

1)      Activity:
Activity is the one which provides screen to the user where he can interact with the application. There should be at least one activity in your Android application to run. Whenever an application icon is clicked any one Activity will be started.

2)      Layout:
Layout is one which defines how your application screen should look like. The layout that we use in the HelloWorld application is RelativeLayout. Which sets the items in a sequence based on other items. In every Android project there will be a folder called LAYOUT in which all the layout design files are stored in XML format.

3)      AndroidManifest.XML:
This file contains the configuration details of our Android application, the minSDK and targetSDK. List of permission that the application need access i.e internet, camera etc.., the first activity that needs to be run when the application launches. What’s the display name of the application, the theme that needs to be used etc.

Below is the file sample file of an Android application.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.skk.helloWorld"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>
</manifest>


4)      Values folder:
This section in the Android project contains the strings, styles, format of the UI elements etc. Below is the sample strings.xml which contains the strings and its values.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Hello Kumar</string>
    <string name="hello_world">Hello Kumar!</string>
    <string name="action_settings">Settings</string>

</resources>


5)      Drawable folders:
This section contains all the images that are used in the Android application. The images with various resolutions are kept in separate folders.

The above are the basic details that needs to be known for a sample application. Details in depth will be explained in separate posts.


Friday, 24 October 2014

Hello World application in Android


This tutorial explains how to create a hello world program in Android.

For setting up the Android development environment check out this blog.

Create a new Android project:

1)      Open the Eclipse IDE, Click on the menu item File à New à Android Application Project

 
2)      Once you select the menu, you will be able to find a screen to enter the details of the new project enter the details as show in the screenshot below.


Application Name: Name that appears to users after the app is installed.
Project Name: Name for uniquely identifying the project
Package Name: Package namespace for your files, this should be unique             across all packages installed on the Android system.
Minimum Required SDK: Lowest version of Android your application supports, to support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature.
Target SDK: Indicated the highest version of Android you have tested the application.
Compile With: Indicated the version with using the program is compiled and build.
Theme: Specifies the Android UI for your App.

The Minimum Required SDK, Target SDK & Compile With are noted with the Android API number.

3)      Just Click on Next in Configure Project screen


4)      You can configure the icon for your application in this screen, select any image icon from your computer. This image will display as the icon for your android application and click Next.


5)      In the Create Activity screen click on Next leaving it to the default selected value “Blank Activity”


6)      Now provide the name for your activity, rename that to SayHello and click on Finish.


7)      This will open a screen similar as below,


8)      Under your project folder structure go to res à Values à strings.xml, change the value of the string hello_world to “Hello Kumar”,  i.e  <string name="hello_world">Hello Kumar!</string>

9)      Just Right Click on your project name select Run As à Android Application.


10)   Once the AVD is launched and the project is deployed you should be able to see the application running successfully as below.


If you go back to the application list page you will be able to see your application with the icon that you selected, sample screen shot below.


Finally successfully we have created the hello world application and ran it successfully.