Chapter 2
Chapter 2
Chapter 2
Android Overview
What is Android
• It is an open source and Linux-based Operating System for mobile
devices such as smartphones and tablet computers.
• Android was developed by the Open Handset Alliance, led by Google,
and other companies.
• Android offers a unified approach to application development for
mobile devices which means developers need only develop for
Android, and their applications should be able to run on different
devices powered by Android.
…
• The first beta version of the Android Software Development Kit (SDK) was
released by Google in November 2007 where as the first commercial
version, Android 1.0, was released in September 2008.
• On June 27, 2012, at the Google I/O conference, Google announced the
next Android version, 4.1 Jelly Bean.
• Jelly Bean is an incremental update, with the primary aim of improving the
user interface, both in terms of functionality and performance.
• The source code for Android is available under free and open source
software licenses. Google publishes most of the code under the Apache
License version 2.0 and the rest, Linux kernel changes, under the GNU
General Public License version 2.
Features of Android
Features of Android…
Android Applications
• Android applications are usually developed in the Java language using
the Android Software Development Kit(SDK).
• Once developed, Android applications can be packaged easily and
sold out either through a store such as Google Play or the Amazon
App store.
• Android powers hundreds of millions of mobile devices in more than
190 countries around the world.
• It's the largest installed base of any mobile platform and growing fast.
Every day more than 1 million new Android devices are activated
worldwide.
Environment Setup
• 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.
• 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
Android Development Tools (ADT) Eclipse Plugin
Step 1 - Setup Java Development Kit (JDK)
• You can download the latest version of Java JDK from Oracle's Java site:
Java SE Downloads and install it.
• 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.
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.
Step 3 - Setup Eclipse IDE
• To install Eclipse IDE, download the latest Eclipse binaries from
http://www.eclipse.org/downloads/.
• Once you downloaded the installation, unpack the binary distribution
into a convenient location.
• After that you can start the .exe file
Step 4 - Setup Android Development Tools (ADT) Plugin
• It will help you in setting Android Development Tool plugin for Eclipse.
• First start Eclipse and then, choose Help > Software Updates > Install
New Software.
Step 5 - Create Android Virtual Device
• To test your Android applications you will need a virtual Android
device.
• before we start writing code, create an Android virtual device.
• Launch Android Virtual Device Manager using Eclipse menu options
Window > Android Virtual Device Manager > which will launch
Android Virtual Device Manager.
• Use New button to create a new Android Virtual Device and enter the
required information and click ok button.
• If your AVD is created successfully it means your environment is ready
for Android application development.
Android Application Architecture
• Android operating system is a stack of software components which is
roughly divided into five sections and four main layers as shown
below in the architecture diagram.
Linux kernel
• At the bottom of the layers is Linux - Linux 2.6 with approximately 115
patches.
• This provides basic system functionality like process management,
memory management, device management like camera, keypad,
display etc. Also, the kernel handles all the things that Linux is really
good at such as networking and a vast array of device drivers, which is
used in interfacing to peripheral hardware.
Libraries
• On top of Linux kernel there is a set of libraries including open-source
Web browser engine WebKit, well known library libc, SQLite database
which is a useful repository for storage and sharing of application
data, libraries to play and record audio and video, SSL libraries
responsible for Internet security etc.
Android Runtime
• It provides a key component called Dalvik Virtual Machine which is a
kind of Java Virtual Machine specially designed and optimized for
Android.
• The Dalvik VM makes use of Linux core features like memory
management and multi-threading, which is intrinsic in the Java
language. The Dalvik VM enables every Android application to run in
its own process, with its own instance of the Dalvik virtual machine.
• The Android runtime also provides a set of core libraries which enable
Android application developers to write Android applications using
standard Java programming language.
Application Framework
• The Application Framework layer provides many higher-level services
to applications in the form of Java classes.
• Application developers are allowed to make use of these services in
their applications.
Applications
• 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 applications are Contacts, Browser, Games etc.
Android Application Components
• Application components are the essential building blocks of an
Android application. These components are loosely coupled by the
application manifest file AndroidManifest.xml that describes each
component of the application and how they interact.
• There are four main components that can be used within an Android
application:
Activities: they dictate the UI and handle the user interaction to the smartphone
screen
Services: They handle background processing associated with an application.
Broadcast Receivers :They handle communication between Android OS and
applications
Content Providers :They handle data and database management issues
Activities
• An activity represents a single screen with a user interface. For
example, an email application might have one activity that shows a
list of new emails, another activity to compose an email, and another
activity for reading emails.
• If an application has more than one activity, then one of them should
be marked as the activity that is presented when the application is
launched.
• An activity is implemented as a subclass of Activity class as follows:
Services
• A service is a component that runs in the background to perform
long-running operations. For example, a service might play music in
the background while the user is in a different application, or it might
fetch data over the network without blocking user interaction with an
activity.
• A service is implemented as a subclass of Service class as follows:
Broadcast Receivers
• Broadcast Receivers simply respond to broadcast messages from
other applications or from the system.
• For example, applications can initiate broadcasts to let other
applications know that some data has been downloaded to the device
and is available for them to use, so this is broadcast receiver who will
intercept this communication and will initiate appropriate action.
• A broadcast receiver is implemented as a subclass of
BroadcastReceiver class and each message is broadcasted as an Intent
object.
Content Providers
• A content provider component supplies data from one application to
others on request. Such requests are handled by the methods of the
ContentResolver class. The data may be stored in the file system, the
database or somewhere else entirely.
• A content provider is implemented as a subclass of ContentProvider
class and must implement a standard set of APIs that enable other
applications to perform transactions.
Additional Components
Anatomy of Android Application
• Before you run your app, you should be aware of a few directories
and files in the Android project:
• Src: it 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: it contains the .R file, a compiler-generated file that references
all the resources found in your project. You should not modify this
file.
• Bin: it contains the Android package files .apk built by the ADT during
the build process and everything else needed to run an Android
application.
Anatomy of Android Application…
• res/drawable-hdpi: This is a directory for drawable objects that are
designed for high-density screens.
• res/layout: This is a directory for files that define your app's user
interface.
• res/values: This is a directory for other various XML files that contain
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.
• example
Thank you