Get Start

What is Android?

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

It was originally developed by a startup of the same name, Android, Inc. In 2005, as part of its strategy to enter the mobile space, Google purchased Android and took over its development work (as well as its development team).

Android Versions

Android Version
Release Date
Code Name
1.0
23 September 2008
--
1.1
9 February 2009
--
1.5
30 April 2009
Cupcake
1.6
15 September 2009
Donut
2.0/2.1
26 October 2009
Eclair
2.2
20 May 2010
Froyo
2.3
6 December 2010
Gingerbread
3.0/3.2/3.3
22 February 2011
Honeycomb
4.0/4.0.3
19 October 2011
Ice Cream Sandwich
4.1/4.2/4.3
9 July 2012
Jelly beans
4.4
31 October 2013
Kit Kat

Android Components

Activities:
An activity represents a single screen with a user interface.

Services:
service is a component that runs in the background to perform long-running operations or to perform work for remote processes

Content providers:
content provider is sharing data between the applications.

Broadcast receivers:
broadcast receiver is a component that responds to system-wide broadcast announcements.

Features of Android

·         Storage Connectivity
·         Messaging
·         Web browser
·         Media support
·         Hardware support
·         Multi-touch
·         Multi-tasking
·         Flash support
·         Tethering


Architecture of Android

Applications

At this top layer, you will find applications that ship with the Android device (such as Phone, Contacts, Browser, etc.), as well as applications that you download and install from the Android Market. Any applications that you write are located at this layer.

Application Framework

Exposes the various capabilities of the Android OS to application developers so that they can make use of them in their applications.

Libraries

These contain all the code that provides the main features of an Android OS. For
example, the SQLite library provides database support so that an application can use it for data storage. The WebKit library provides functionalities for web browsing.

Android Runtime

At the same layer as the libraries, the Android runtime provides a set of core libraries that enable developers to write Android apps using the Java programming language. The Android runtime also includes the Dalvik virtual machine, which enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine.

Dalvik virtual machine
Android applications are compiled into the Dalvik executables (.dex). Dalvik is a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU.

Linux kernel

This is the kernel on which Android is based. This layer contains all the low level device drivers for the various hardware components of an Android device.



Play Store (Android Market)

 As such, in August 2008, Google announced the Android Market, an online application store for Android devices, and made it available to users in October 2008. Using the Market application that is preinstalled on their Android device, users can simply download third-party applications directly onto their devices. Both paid and free applications are supported on the Android Market, though paid applications are available only to users in certain countries due to legal issues.

Development Tools

Android SDK

The next important piece of software you need to download is, of course, the Android SDK. The Android SDK contains a ADT, debugger, libraries, an emulator, documentation, sample code, and tutorials.  You can download the Android SDK from here.

Once the SDK is downloaded, unzip its content into the C:\Android\ folder, or whatever name you have given to the folder you just created. You will have the below items:

·         eclipse (Folder) - IDE
·         sdk (Folder) - Android Software development kit
·         SDK Manager (File) -  Android Software development kit Manager


Android Development Tools (ADT-Eclipse)

The ADT Bundle provides everything you need to start developing apps, including a version of the Eclipse IDE with built-inADT (Android Developer Tools) to streamline your Android app development. You can do the following operations with ADT.

·         Create new Android application projects.
·         Access the tools for accessing your Android emulators and devices.
·         Compile and debug Android applications.
·         Run the Application.
·         Export Android applications into Android Packages (APK).
·         Create digital certificates for code-signing your APK.

Creating Android Virtual Devices (AVD s)

The next step is to create AVD to be used for testing your Android applications. AVD stands for Android Virtual Devices. An AVD is an emulator instance that enables you to model an actual device. Each AVD consists of a hardware profile, a mapping to a system image, as well as emulated storage, such as a secure digital (SD) card. You can create as many AVDs as you want in order to test your applications with several different configurations. This testing is important to confirm the behaviour of your application when it is run on different devices with varying capabilities.

Follow the below steps to create AVD:

1.       Start the AVD Manager:
o    In Eclipse: select Window > AVD Manager, or click the AVD Manager icon in the Eclipse toolbar.
o    In other IDEs: Navigate to your SDK's tools/ directory and execute the android tool with no arguments.
2.       In the Virtual Devices panel, you'll see a list of existing AVDs. Click New to create a new AVD. The Create New AVD dialog appears.

3.       Fill in the details for the AVD.
Give it a name, a platform target, an SD card size, and a skin (HVGA is default). You can also add specific hardware features of the emulated device by clicking the New... button and selecting the feature. For a list of hardware features, see Hardware options.
Note: Be sure to define a target for your AVD that satisfies your application's Build Target (the AVD platform target must have an API Level equal to or greater than the API Level that your application compiles against).

4.       Click Create AVD.
Your AVD is now ready and you can close the AVD Manager, create more AVDs, or launch an emulator with the AVD by selecting a device and clicking Start.
Anatomy of an Android Application

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.

Android 4.4 library: This item contains one file, android.jar, which contains all the class libraries needed for an Android application.

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.

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.

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.).



Hello World Application

To create an Android project using Eclipse, you need to supply the information shown in Table:

Properties
Description
Project name
The name of the project
Application
A user-friendly name for your application
Package name
The name of the package You should use a reverse domain name for this.
Create Activity
The name of the first activity in your application
Min SDK Version
The minimum version of the SDK that your project is targeting


The main.xml file defines the user interface for your activity. Observe the following code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="vertical" >
<TextView
 android:layout_width=”fill_parent”
 android:layout_height=”wrap_content”
 android:text=”@string/hello”
/>
</LinearLayout>


The @string in this case refers to the strings.xml file located in the res/values folder. Hence, @string/hello refers to the hello string defined in the strings.xml file, which is “Hello World, MainActivity!”:

<?xml version=”1.0” encoding=”utf-8”?>
<resources>
<string name=”hello”>Hello World, MainActivity!</string>
<string name=”app_name”>HelloWorld</string>
</resources>

It is recommended that you store all the string constants in your application in this strings.xml file and reference these strings using the @string identifier. That way, if you ever need to localize your application to another language, all you need to do is replace the strings stored in the strings.xml file with the targeted language and recompile your application.

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=”android.rajesh.calendar”
android:versionCode=”1”
android:versionName=”1.0”>

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

<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 android.rajesh.calendar.
·         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 net.learn2develop.HelloWorld;
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;
  }
}

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.

Finally, the code that connects the activity to the UI (main.xml) is the setContentView() method, which is in the MainActivity.java file:

package net.learn2develop.HelloWorld;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Here, R.layout.main refers to the main.xml file located in the res/layout folder. As you add additional XML files to the res/layout folder, the filenames will automatically be generated in the R.java file. The onCreate() method is one of many methods that are fired when an activity is loaded.