First Application

First Application

4.2 First Application : FirstApp

For my first application,

I have made an application which has two buttons and a counter which shows the final result.

This app basically uses a variable,

which is set to zero initially, and when we click the add one button it adds one to the current

value of the variable.

Similarly,

when we click on the subtract one button,

it subtracts one from the current value of the variable.

On clicking the “Add one” button, 1 is added to the current total.

On clicking the “Subtract one” button, 1 is subtracted from the current total.

 

Screenshot from 2013-11-14 16:56:23

 

Screenshot from 2013-11-14 16:55:52

Android Project

Chapter 1:

I have started working on Android and hereby I am making up my notes, for references,

for myself and for others.

Chapter 2: Introduction to Project

2.1 What is android ?

Android is basically an operating system for smartphones. But we find now integrated into PDAs,

touch pads or televisions, even cars (trip computer) or netbooks. The OS was created by the start-up of the same name,

which is owned by Google since 2005 .

2.2 Specifications :

This operating system is based on version 2.6 of Linux, so it has a monolithic system kernel, what

means that all system functions and drivers are grouped into one block of code.

• Architecture :

Android consists of five layers:

-The Linux kernel 2.6-which includes useful drivers that allow for example WiFi or Bluetooth.

-The library written in C and C + + that provide higher level functionality such as an HTML engine, or a database (SQLite).

-A runtime environment for applications based on a virtual machine, made for inefficient machines such as telephones. The aim is to translate JAVA in machine language understood by Android.

-A JAVA framework that allows applications running on the virtual machine to organize and cooperate.

-The user applications written in Java (Web browser, contact manager etc. ..)

 Current Version

Today android is in its 5th version, Android 4.4. Each version is designed to gradually correct the lack of APIs,

to enhance the user interface and add functionality.

Android 1.0 (API level 1)

Android 1.0, the first commercial version of the software, was released on 23 September 2008.

The first commercially available Android device was the HTC Dream.

Android 1.1 (API level 2)

On 9 February 2009, the Android 1.1 update was released, initially for the HTC Dream only.

Android 1.1 was known as “Petit Four” internally, though this name was not used officially.

The update resolved bugs, changed the Android API and added a number of features.

Android 1.5 Cupcake (API level 3)

On 27 April 2009, the Android 1.5 update was released, based on Linux kernel 2.6.27.

This was the first release to officially use a codename based on a dessert item (“Cupcake”), a theme which would be used for all releases henceforth. The update included several new features and UI amendments.

Android 1.6 Donut (API level 4)

On 15 September 2009, the Android 1.6 SDK – dubbed Donut – was released, based on Linux kernel 2.6.29. Included in the update were numerous new features.

Android 2.0 Eclair (API level 5)

On 26 October 2009, the Android 2.0 SDK – codenamed Eclair – was released, based on Linux kernel 2.6.29.

Android 2.0.1 Eclair (API level 6)

3 December 2009

Android 2.1 Eclair (API level 7)

12 January 2010

Android 2.2–2.2.3 Froyo (API level 8)

On 20 May 2010, the SDK for Android 2.2 (Froyo, short for frozen yogurt) was released, based on Linux kernel 2.6.32.

Android 2.3–2.3.2 Gingerbread (API level 9)

On 6 December 2010, the Android 2.3 (Gingerbread) SDK was released, based on Linux kernel 2.6.35.

Android 2.3.3–2.3.7 Gingerbread (API level 10)

9 February 2011-21 September 2011

Android 3.0 Honeycomb (API level 11)

On 22 February 2011, the Android 3.0 (Honeycomb) SDK – the first tablet-only Android update – was released, based on Linux kernel 2.6.36. The first device featuring this version, the Motorola Xoom tablet, was released on 24 February 2011.

Android 3.1 Honeycomb (API level 12)

10 May 2011[67]

Android 3.2 Honeycomb (API level 13)

15 July 2011[71]

Android 4.0–4.0.2 Ice Cream Sandwich (API level 14)

The SDK for Android 4.0.1 (Ice Cream Sandwich), based on Linux kernel 3.0.1, was publicly released on 19 October 2011. Google’s Gabe Cohen stated that Android 4.0 was “theoretically compatible” with any Android 2.3.x device in production at that time. The source code for Android 4.0 became available on 14 November 2011. Ice Cream Sandwich was the last version to officially support Adobe Systems’ Flash player.

Android 4.0.3–4.0.4 Ice Cream Sandwich (API level 15)

16 December 2011

Android 4.1 Jelly Bean (API level 16)

Google announced Android 4.1 (Jelly Bean) at the Google I/O conference on 27 June 2012. Based on Linux kernel 3.0.31, Jelly Bean was an incremental update with the primary aim of improving the functionality and performance of the user interface. The performance improvement involved “Project Butter”, which uses touch anticipation, triple buffering, extended vsync timing and a fixed frame rate of 60 fps to create a fluid and “buttery-smooth” UI. Android 4.1 Jelly Bean was released to the Android Open Source Project on 9 July 2012, and the Nexus 7 tablet, the first device to run Jelly Bean, was released on 13 July 2012.

Android 4.2 Jelly Bean (API level 17)

Google was expected to announce Jelly Bean 4.2 at an event in New York City on 29 October 2012, but the event was cancelled due to Hurricane Sandy. Instead of rescheduling the live event, Google announced the new version with a press release, under the slogan “A new flavor of Jelly Bean”. Jelly Bean 4.2 was based on Linux kernel 3.4.0, and debuted on Google’s Nexus 4 and Nexus 10, which were released on 13 November 2012.

Android 4.3 Jelly Bean (API level 18)

Google released Jelly Bean 4.3 under the slogan “An even sweeter Jelly Bean” on 24 July 2013 during an event in San Francisco called “Breakfast with Sundar Pichai”. Most Nexus devices received the update within a week, although the 2nd generation Nexus 7 tablet was the first device to officially ship with it. A minor bugfixing update was released on 22 August 2013.

Android 4.4 KitKat (API level 19)

Google announced Android 4.4 KitKat, internally known as Project Svelte, on 3 September 2013.[123] The release had long been expected to be numbered 5.0 and called ‘Key Lime Pie’. KitKat debuted on Google’s Nexus 5, and has been optimised to run on a larger range of devices, with at least 512 MB of RAM.

2.3 Characteristic of the market:

• Competitors

-iPhone OS: The principal competitor is iPhone OS. It is mainly for competing with Apple that Android has been created.

-Palm OS devices on PDA.

-Blackberry: which team the same name smartphones

-Windows Mobile: which team smartphones and PDAs.

• Key partners

To help launch Android, Google has created an alliance of thirty companies in order to develop

standards for mobile devices. There is, among others:

-Operators such as NTT Dokomo, T-Mobile or Bouygues Telecom

-Of-equipment manufacturers like Sony Ericsson or Samsug

-Manufacturers of semiconductors, including Intel and Nvidia

-Corporate businesses.

• Market share

The android market share continues to increase since its inception, and is likely to continue

climbing because it is favored by big players like HTC , Sony Ericsson, Samsung, LG, Motorola, Dell, Acer .

Moreover, according to IDC, android will be the leading mobile operating system used of the market in 2013.

Here is the state of the market from 2006 to 2009. You have to know that the first mobile phone appeared ,

in android dated October 2008.

As of November 2013, Android’s share of the smartphone market is said to have reached 80%.

Indeed, during August, Semptember, and October 2013, no less then 261.1 million smartphones were sold overall, with about 211 million smarthphones running Google’s operating system.

(fig. 4)

2.4 Why Android is better ?

Applications

– google applications

Android includes most of the time many Google applications like Gmail, YouTube or Maps.

These applications are delivered with the machine most of the time, except in certain cases,

such as some ,

phones running android on which the provider has replaced Google applications by its own applications.

-widgets

With android, it is possible to use widgets which are small tools that can most often get

information. These widgets are directly visible on the main window.

-Android Market

This is an online software store to buy applications. Developers who created applications

can add them into the store, and these applications can be downloaded by users, they can be both free and paid.

Multitasking

Android allows multitasking in the sense that multiple applications can run simultaneously.

With Task Manager it is possible view all running tasks and to switch from one to another easily.

SDK

A development kit has been put at disposal of everybody. Accordingly, any developer can create their own applications, or change the android platform.

This kit contains a set of libraries, powerful tools for debugging and development, a phone emulator, thorough documentation, FAQs and tutorials.

• Modifiability

This allows everyone to use, improve or transform the functions of Android for example transform

the interface in function of uses , to transform the platform in a real system embedded Linux.

Chapter 3: Product Design

3.1 Prerequisites

Android programming is based on Java programming language so if you need to have basic understanding on Java programming then it will be a fun to do Android application development.

You will be glad to know that you can start your Android application development on either of the following operating systems:

Microsoft Windows XP or later version.

Mac OS X 10.5.8 or later version with Intel chip.

Linux including GNU C Library 2.7 or later.

Second point is that all the required tools to develop Android applications are freely available and can be downloaded from the Web.

Following is the list of software’s you will need before you start your Android application programming.

Java JDK5 or JDK6

Android SDK

Eclipse IDE for Java Developers (optional)

Android Development Tools (ADT) Eclipse Plugin (optional)

Here last two components are optional and if you are working on Windows machine then these components make your life easy while doing Java based application development. So let us have a look how to proceed to set required environment.

3.2 Step 1 – Setup Java Development Kit (JDK)

You can download the latest version of Java JDK from Oracle’s Java site: Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.

If you are running Windows and installed the JDK in C:\jdk1.6.0_15, you would have to put the following line in your C:\autoexec.bat file.

set PATH=C:\jdk1.6.0_15\bin;%PATH%

set JAVA_HOME=C:\jdk1.6.0_15

Alternatively, you could also right-click on My Computer, select Properties, then Advanced, then Environment Variables. Then, you would update the PATH value and press the OK button.

On Linux, if the SDK is installed in /usr/local/jdk1.6.0_15 and you use the C shell, you would put the following code into your .cshrc file.

setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH

setenv JAVA_HOME /usr/local/jdk1.6.0_15

Alternatively, if you use an Integrated Development Environment (IDE) Eclipse, then it will know automatically where you have installed your Java.

3.3 Step 2 – Setup Android SDK

You can download the latest version of Android SDK from Android official website : Android SDK Downloads. If you are installing SDK on Windows machine, then you will find a installer_rXX-windows.exe, so just download and run this exe which will launch Android SDK Tool Setup wizard to guide you throughout of the installation, so just follow the instructions carefully. Finally you will have Android SDK Tools installed on your machine.

If you are installing SDK either on Mac OS or Linux, check the instructions provided along with the downloaded android-sdk_rXX-macosx.zip file for Mac OS and android-sdk_rXX-linux.tgz file for Linux.

So let’s launch Android SDK Manager using the option All Programs > Android SDK Tools > SDK Manager, this will give you following window:

(fig. 5)

Once you launched SDK manager, its time to install other required packages. By default it will list down total 11 packages to be installed, but I will suggest to de-select Documentation for Android SDK and Samples for SDK packages to reduce installation time. Next click Install 11 Packages button to proceed.

3.4 Step 3 – Install the Eclipse IDE

In this step, you download and install the Eclipse IDE. Do the following to install Eclipse in your system:

Download the Eclpse IDE for Java developers.

Move the tar file into your home directory.

Expand the tar file, using the command,

tar -xvzf eclipse-jee-indigo-SR2-macosx-cocoa.tar.gz

When you are done, you will have an eclipse directory in your home directory.

(fig. 6)

3.5 Step 5 – Create Android Virtual Device

To test your Android applications you will need a virtual Android device. So before we start writing our code, let us create an Android virtual device.

Launch Android AVD Manager using Eclipse menu options Window > AVD Manager> which will launch Android AVD Manager. Use New button to create a new Android Virtual Device and enter the following information, before clicking Create AVD button.

If your AVD is created successfully it means your environment is ready for Android application development. If you like, you can close this window using top-right cross button. Better you re-start your machine and once you are done with this last step, you are ready to proceed for your first Android example but before that we will see few more important concepts related to Android Application Development.

(fig. 8)

Chapter 4: Development and Implementation

4.1 The basics of creating applications

To begin to program for Android I needed some basics, because some elements are very different,

even if programming an application in Android uses the Java language, therefore, an object oriented

language.

Firstly, in an Android application, there is no main method:

public static void main(String[] args){…}

This method that allows to launch a program in java is not present in an application android. This

example is only the first of a long list.

Application Fundamentals ::

Activity :

An activity is a user interface that allows the user to interact with the screen, to perform actions.

For example, a text messaging application could have an activity that displays a list of contacts to send messages.

Once the contact is selected , activity could send information to a second activity that could serve to send the message to the contact.

When an application is launched, what it displays is the result of an activity. At the code level, for

create an activity , you must create a class that extends the Activity class. An activity has a required

onCreate () method. It is the main method. To interact with the program, through the activity,

there must be something displayed, that is why the activity, contains what is called views.

Service :

A Service is an application component that can perform long-running operations in the background and does not provide a user interface.

Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally,

a component can bind to a service to interact with it and even perform interprocess communication (IPC).

For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background.

Intent :

Three of the core components of an application — activities, services, and broadcast receivers

— are activated through messages, called intents.

Intent messaging is a facility for late run-time binding between components in the same or different applications. The intent itself,

an Intent object, is a passive data structure holding an abstract description of an operation to be performed — or,

often in the case of broadcasts, a description of something that has happened and is being announced.

Android Manifest :

AndroidManifest.xml file is necessary for all android applications and must have this name in its

root directory. In the manifest you can find essential informations about the application for the Android system,

informations that the system must have before it can run any of the application’s code.

Here is what you can find in the Android manifest:

-The name of the Java package for the application. The package name serves as a unique identifier

for the application.

-The description of the components of the application : the activities, services, broadcast receivers,

and content providers that the application is composed of and under what conditions they can be

launched .

-The processes that will host application components.

-The permissions the application must have in order to access protected parts of the API and

interact with other applications.

-The permissions that others are required to have in order to interact with the application’s components.

-The list of the Instrumentation classes that provide profiling and other information as the

application is running. These declarations are present in the manifest only while the application is being developed and tested; they’re removed before the application is published.

-The minimum level of the Android API that the application requires.

-The list of the libraries that the application must be linked against.

User Interface :

All user interface elements in an Android app are built using View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with.

A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.

Android provides a collection of both View and ViewGroup subclasses that offer you common input controls (such as buttons and text fields) and

various layout models (such as a linear or relative layout).

XML :

Using Android’s XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements.

Each layout file must contain exactly one root element, which must be a View or ViewGroup object. Once you’ve defined the root element,

you can add additional layout objects or widgets as child elements to gradually build a View hierarchy that defines your layout.

Toast :

A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive.

For example,

navigating away from an email before you send it triggers a “Draft saved” toast to let you know that you can continue editing later.

Toasts automatically disappear after a timeout.