of 13
7/28/2019 Android Basics and Architecture
1/13
Android overview
Android is a mobile operating system development by Google. It is used by several Smartphone such as
the Motorola Droid. Samsung Galaxy, and Googles own Nexus One.
The Android Operating System (OS)is based the open Linux Kernel. Unlike the iphone os,Android is open
source,meaning developers can modify and customize the os for each phone.Therefore diffenent
Android-based phones may have different graphical user interface,even though they use the same os.
World is contracting with the growth of mobile phone technology. As the number of users is increasing
day by day, facilities are also increasing. Starting with simple regular handsets which were used just for
making phone calls, mobiles have changed our lives and have become part of it. Now they are not used
just for making calls but they have innumerable uses and can be used as a Camera , Music player, Tablet
PC, T.V. , Web browser etc . And with the new technologies, new software and operating systems are
required.
What is Android?Operating Systems have developed a lot in last 15 years. Starting from black and white phones to recent
smart phones or mini computers, mobile OS has come far away. Especially for smart phones, Mobile OS
has greatly evolved from Palm OS in 1996 to Windows pocket PC in 2000 then to Blackberry OS and
Android.
One of the most widely used mobile OS these days is ANDROID. Android is a software bunch comprised
not only operating system but also middleware and key applications. The application executes within its
own process and its own instance of Dalvik Virtual Machine. Many Virtual Machines run efficiently by a
DVM devices.DVM executes java languages byte code which latter transform into .dex format files.
Version history of Android operating system1. Android 1.0 -Release Date: September 23, 2008
2. Android 1.1 - Release Date: February 9, 2009
3. Android 1.5 Cupcake Release Date: April 30, 2009
4. Android 1.6 Donut - Release Date: September 15, 2009
5. Android 2.0/2.1 clair Release Date: October 26, 2009
6. Android 2.2 FroYo Release Date: May 20, 2010
7. Android 2.3 Gingerbread - Release Date: December 6, 2010
7/28/2019 Android Basics and Architecture
2/13
8. Android 3.0 Honeycomb - Release Date: February 22, 2011
9. Android 4.0 Ice Cream Sandwich - Release Date: October 19, 2011
10. Android 4.1 Jelly Bean - Release Date: July 9, 2012.
Application FundamentalAndroid applications are written in the Java programming language. The android SDK(Software
Development Kit)tools compile the code, along with any data and resources file, into an Android
package, an archive file with an .apk suffix.
All the code is single .apk file is considered to be one application and is the file that Android powered
devices use to install the application.
How install SDK into eclipse?Step 1::
Step 2::
7/28/2019 Android Basics and Architecture
3/13
Step ::3
Dalvik Virtual Machines (DVM):
Dalvik virtual machine (DVM) is a process virtual machine which is part of an open source the Android
mobile phone platform based on the Linux operating system and is developed by the OHA (Open
Handset Alliance) which is a consortium of companies including Google, HTC (High Tech Computer
Corporation-Taiwan), Intel, Motorola, Qualcomm, T-Mobile, and NVIDIA. The DVM was originally
developed by Dan Bornstein. The others who contributed along with Dan Bornstein were mainly
engineers from Google as part of the Android mobile phone platform.
The DVM operates on byte codes that are transformed from the Java Class files compiled by a Java
compiler into another class file format called the .dex format using a dx tool which is included in the
Android SDK (Software Development Kit). The primary goal of the DVM which is creation of platform
neutral dex files is comparable to the Java Virtual Machine (JVM) which processes the Java byte codes
while using Java Class files or Jar files. The processes of the DVM are typically optimized for the low
memory requirements needed for development and implementation of applications for the mobile
phone platform. It is designed to allow multiple VM instances to run at once.
Android Emulator:
The Android SDK includes a mobile device emulator, a virtual mobile device that runs on your computer.
The emulator lets you develop and test Android application without using a physical device.
7/28/2019 Android Basics and Architecture
4/13
How create Emulator?Step:1
Step:2
7/28/2019 Android Basics and Architecture
5/13
7/28/2019 Android Basics and Architecture
6/13
Step:5
Class Overview of ActivityAn activity represents the visual representation of an Android application. Activity use views, i.e. user
interface widgets as for example buttons and fragments to create the user interface and to interact with
the user. An activity is a single, focused thing that the user can do. Almost all activities interact with the
user, so the Activity class takes care of creating a window for you in which you can place your UI with
setContentView (View). While activities are often presented to the user as full-screen windows, they can
also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded
inside of another activity (using Activity Group).
7/28/2019 Android Basics and Architecture
7/13
7/28/2019 Android Basics and Architecture
8/13
When we launch an Activity in Android, it first calls the onCreate() method. This is where we doUser Interface creation and initialization of data elements. This method is provided with a
Bundle object as parameter to restore the UI state.
onStart() method is called before the Activity is being visible to the User. Remember thatActivity is still not Active.
With the onResume() method, the Activity become visible and Active for the user to interactwith. The Activity will be at the top of the Activity stack at this point. Now the Activity is in
running /active state and is able to receive user inputs.
In the Active state, onPause() method will be called when the system is about to resumeanother Activity on top of this one or when the user is about to navigate to some other other
parts of the system. It is the last guaranteed call to a method before the Activity can get killed
by the system. That is, theres a possibility that your activity may be killed by the system at the
paused state without executing any further method calls. Therefore it is important to save the
user interface configuration and critical data at this method.
By default, an Activity can remain in the paused state if: The user has pressed the home button Another activity or notification which is on top of it doesnt completely obscures
the visibility of underlying Activity.
The device goes to sleep. There are three possibilities for an Activity under paused state:1. The user resumes the Activity by closing the new Activity or notification and the paused Activity
gets Active/Running by calling onResume() method.
2. It gets killed by the system under extremely low memory conditions. In this case there will beno further method calls before the destruction of the Activity and it needs to be re-run from the
beginning by calling onCreate() and restoring the previous configuration from bundle object.
In all other cases it goes to stopped state by executing onStop() method. This is the default action when
the user has pressed the back button, or a new activity which completely covers it resumes on top.
An Activity under stopped state also has three different scenarios to happen:1. System kills it to free resources. An activity under stopped sate is more likely to be killed by the
system than one in the paused state. It needs to start the cycle again with onCreate().
2. It get restarted by calling onRestart() , onStart() and onResume() methods in the order if theuser navigates back to the Activity again. In this case, the User Interface is intact and no need to
be restored.
3. onDestroy() method is called and the Activity is destroyed. This is the final method we can callbefore the Activity is destroyed. This occurs either because the Activity is finishing the operation
or the system is temporarily destroying it to save space..
Android Activity Lifecycle Loops
By analyzing the Android Activity lifecycle diagram we can see there are three lifecycle loops exist for
every Activity and are defined by those callback methods.
7/28/2019 Android Basics and Architecture
9/13
They are:
1. Entire Lifetime: This is the lifetime between the first call to the onCreate() and the finalcall to onDestroy() method. We create all global resources such as screen layout, globalvariables etc in onCreate() and release all resources with onDestroy() call.
2.
Visible Lifetime: It is the lifetime of an Activity between onStart() andonStop()method calls. In this the Activity is visible to the user and he may or may not be able tointeract with it. During the visible lifetime, an Activity maintains its state intact.
3. Foreground Lifetime: Foreground lifetime starts with onResume() and ends withonPause() method calls. During this, the Activity is completely visible to the user and is
on top of all other Activities so that user can interact with it.
Android Architecture
The above figure shows the diagram of Android Architecture. The Android OS can be referred to as a
software stack of different layers, where each layer is a group of several program components. Together
it includes operating system, middleware and important applications. Each layer in the architecture
provides different services to the layer just above it. We will examine the features of each layer in detail.
7/28/2019 Android Basics and Architecture
10/13
Linux Kernel
The basic layer is the Linux kernel. The whole Android OS is built on top of the Linux 2.6
Kernel with some further architectural changes made by Google. It is this Linux that interactswith the hardware and contains all the essential hardware drivers. Drivers are programs that
control and communicate with the hardware. For example, consider the Bluetooth function. Alldevices has a Bluetooth hardware in it. Therefore the kernel must include a Bluetooth driver to
communicate with the Bluetooth hardware. The Linux kernel also acts as an abstraction layerbetween the hardware and other software layers. Android uses the Linux for all its core
functionality such as Memory management, process management, networking, security settingsetc. As the Android is built on a most popular and proven foundation, it made the porting of
Android to variety of hardware, a relatively painless task.
Libraries
The next layer is the Androids native libraries. It is this layer that enables the device to handle
different types of data. These libraries are written in c or c++ language and are specific for aparticular hardware.
Some of the important native libraries include the following:
Surface Manager: It is used for compositing window manager with off-screen buffering. Off-screen buffering means you cant directly draw into the screen, but your drawings go to the off-
screen buffer. There it is combined with other drawings and form the final screen the user willsee. This off screen buffer is the reason behind the transparency of windows.
Media framework: Media framework provides different media codecs allowing the recordingand playback of different media formats
SQLite: SQLite is the database engine used in android for data storage purposes
WebKit: It is the browser engine used to display HTML content
OpenGL: Used to render 2D or 3D graphics content to the screen
Android Runtime
Android Runtime consists of Dalvik Virtual machine and Core Java libraries.
Dalvik Virtual Machine
It is a type of JVM used in android devices to run apps and is optimized for low processingpower and low memory environments. Unlike the JVM, the Dalvik Virtual Machine doesnt run
.class files, instead it runs .dex files. .dex files are built from .class file at the time of compilationand provides hifger efficiency in low resource environments. The Dalvik VM allows multiple
7/28/2019 Android Basics and Architecture
11/13
instance of Virtual machine to be created simultaneously providing security, isolation, memorymanagement and threading support. It is developed by Dan Bornstein of Google.
Core Java LibrariesThese are different from Java SE and Java ME libraries. However these libraries provides most
of the functionalities defined in the Java SE libraries.
Application Framework
These are the blocks that our applications directly interacts with. These programs manage the
basic functions of phone like resource management, voice call management etc. As a developer,you just consider these are some basic tools with which we are building our applications.
Important blocks of Application framework are:
Activity Manager: Manages the activity life cycle of applications
Content Providers: Manage the data sharing between applications
Telephony Manager: Manages all voice calls. We use telephony manager if we want to accessvoice calls in our application.
Location Manager: Location management, using GPS or cell tower
Resource Manager: Manage the various types of resources we use in our Application
Applications
Applications are the top layer in the Android architecture and this is where our applications are
gonna fit. Several standard applications comes pre-installed with every device, such as:
SMS client app Dialer Web browser Contact manager
As a developer we are able to write an app which replace any existing system app. That is, youare not limited in accessing any particular feature. You are practically limitless and can whatever
you want to do with the android (as long as the users of your app permits it). Thus Android isopening endless opportunities to the developer.
7/28/2019 Android Basics and Architecture
12/13
Android Project folder structure
f
SrcUser specified java source code files will be available here.
gen
The gendirectory in an Android project contains auto generated files. You can see R.java inside this
folder which is a generated class which contains references to certain resources of the project. R.java isautomatically created by the Eclipse IDE and any manual changes are not necessary
assets
This folder contains raw hierarchy of files and directories, with no other capabilities. It is just an
unstructured hierarchy of files, allowing you to put anything you want there and later retrieve as raw
byte streams.
7/28/2019 Android Basics and Architecture
13/13
res
Android supports resources like images and certain XML configuration files, these can be keep separate
from the source code. All these resources should be placed inside the res folder. This res folder will be
having sub-folders to keep the resources based on its type.
/res/values
Used to define strings, colors, dimensions, styles and static arrays of strings or integers. By convention
each type is stored in a separate file, e.g. strings are defined in the res/values/strings.xml fil
/res/layout
This folder contains the layouts to be used in the application.A layout resource defines the architecture for
the UI in an Activity or a component of a UI. These are resource directories in an application that
provides different layout designs for different screen sizes
/res/values
Used to define strings, colors, dimensions, styles and static arrays of strings or integers. By conventioneach type is stored in a separate file, e.g. strings are defined in the res/values/strings.xml file.
AndroidManifest.xml
All the android applications will have an AndroidManifest.xml file in the root directory. This file will
contain essential information about the application to the Android system, information the system must
have before it can run any of the application's code. This control file describes the nature of the
application and each of its components