Tuesday, 4 March 2014

Getting started with Android Application Development (Hello World Example)

Here we will learn how to create a simple "Hello World" Android project in Eclipse IDE using ADT plugin and run it with Android Virtual Device.
The required tools for Android development are :
  1. JDK 1.6
  2. Eclipse IDE
  3. Android SDK
To develop the Android application, we will follow the below steps : 
  1. Download and install the Android SDK
  2. Download and install the ADT Eclipse plugin
  3. Create an Android Virtual Device(ADT)
  4. Create an Android Project in Eclipse
  5. Run the application in Android Virtual Device

Download and install the Android SDK

Go to the Android SDK Page and download the appropriate version for your platform. You can download the ADT(Android Development Tool) bundle, in which you will find both Eclipse and Android SDK. After installation on running the sdkmanager.exe following window will appear.


Download and install the ADT Eclipse plugin

In this step we are going to integrate the Android SDK with Eclipse by using ADT plugin.
Open Eclipse and select Help-->Install New Software. Here we will get a window with a edit field to put the following URL and click Add.

https://dl-ssl.google.com/android/eclipse


Create an Android Virtual Device(AVD)

After the installation of the ADT plugin, restart the Eclipse. After restarting the Eclipse, you will get two Android Development icon on the Eclipse Toolbar.


These icon launches the SDK Manager and AVD Manager respectively. On launching the AVD Manager, a window will appear.


Click on NEW to create the new AVD.



Create the Android Project in Eclipse

  1. To create the new project go to File-->New-->other-->Android-->Android Application Project.(OR ctrl+n--->Android-->Android Application Project.)




Enter the Application name, Project name and Package name. Choose a Build SDK that suits your test devices and favored  emulator configuration.


Here, the package name should not begin with any of the following values(not allowed in Google Play ):
  • com.android
  • com.google
  • android
  • com.example
  • com.test
Click Next, a window will appear for configuring launcher icon. You can always change the launcher icon later.




Click Next, another window for creating Activity will appear. Here select Blank Activity.


Click Next, again new window for specify Activity details


On click on Finish, you will get the project in Project Explorer in Eclipse. Here is the structure of the project


src

This contains the .java source files for your project. By default, it includes an MainActivity.java source file having an activity class that runs when your app is launched using the app icon.

gen

This contains the .R file, a compiler-generated file that references all the resources found in your project. You should not modify this file.

bin

This contains the .APK(Android package file) built by the ADT during the building process and everything else needed to run the an Android application.

res/drawable-hdpi

This contains drawable objects that designed for high-density screen

res/layout

This contains the file that define app's user interface. 

res/values

This contains the other various XML files contains a collection of resources, such as strings and colors definitions.

AndroidManifest.xml

This is the manifest file which describes the fundamental characteristics of the app and defines each of its components.


The Main Activity File

The main activity code is in a java file MainActivity.java. This is the actual application file which ultimately get converted to Dalvik executable and runs application.

 package com.company.basichelloworld;  
 import android.os.Bundle;  
 import android.app.Activity;  
 import android.view.Menu;  
 public class MainActivity extends Activity {  
      @Override  
      protected void onCreate(Bundle savedInstanceState) {  
           super.onCreate(savedInstanceState);  
           setContentView(R.layout.activity_main);  
      }  
      @Override  
      public boolean onCreateOptionsMenu(Menu menu) {  
           // Inflate the menu; this adds items to the action bar if it is present.  
           getMenuInflater().inflate(R.menu.main, menu);  
           return true;  
      }  
 } 

This onCreat() method is called first time when activity is started and application is not loaded. But for subsequent start of the activity, the onCreat() method of application will not bne called.
setContentView() load the UI for the respective activity. R.layout.activity_main refers the activity_main.xml located in res/layout folder.


                                 





Friday, 21 February 2014

Introduction to Android

Android is the world's most popular operating system for mobile devices and tablets. It is an open source operating system, created by Google, and available to all kinds of developers with various expertise levels, ranging from rookie to professional.
(Well, open-source means software with source available for modification and bound to an open sourec licence agreement.)

From developer's perspective, android is a Linux-based operating system for smartphones and tablets. It includes a touch screen user interface, widget, camera, network data monitoring and all the other features that enables a cell phone to be called a smartphone. Android is a platform that supports various applications, available through the Google Play Store. 

Like most software , Android is released in versions. Google has also names to it versions since April 2009. Below are all the version of Android released to date :  


Android Version Update


                                    

Android Architecture

To begin with development on Android even at the application level, it is paramount to understand the basic internal architecture. Knowing how things are arranged inside helps us to understand the application framework better, so we can design the application in a better way.
Android operating system is a stack of software components which is roughly divided into five section and four layers as shown in the architecture diagram.



Android architecture


Linux Kernel

The Android OS is derived from Linux Kernel 2.6 and is actually created from Linux source with approximately 115 patches, complied for mobile devices. This provide basic system functionality like process management, memory management, device management like camera, keypad, display etc. The kernel acts as a Hardware Abstraction Layer between hardware and the Android software stack.

Libraries

This layer holds the android native libraries. These libraries are written in C/C++ and offer capabilities similer to the above layer, while sitting on top of the kernel. A few of the major native libraries include
  • Surface Manager
  • System C Libraries
  • OpenGL ES Libraries
  • SQLite

Android Runtime

This is the third section of the architecture and available on the second layer from the bottom. This section provides a key component called Dalvik Virtual Machine(DVM). It is basically a virtual machine for embedde device, which like any other virtual machine is a bytecode interpreter. when we say it is for embedded device, it means it is low on memory, comparatively slower and runs on battery power. The Dalvik VM makes use of Linux core feature like memory management and multi-threading, which is intrinsic in the Java language. The Dalvik VM enables every Android application to run its own process, with its own instance of DVM. 
The Android runtime also provides a set of core libreries which enable Android application developers to write Android applications using standard Java programming language.

Application Framework

This is the fourth section of the architecture, which application developers can leverage in developing Android application. The framework offers a huge set of APIs used by developers for various standard purpose, so that they don't have to code every basic task.

Application

You will find all the Android application at the top layer. You will write your application to be installed on this layer only. Examples of such application are Browser, Games etc.