Unit 1 Introduction of Android
Unit 1 Introduction of Android
Unit 1 Introduction of Android
5. Installation
6. Android SDK
8. Application Context
9. Application Tasks
Android is an operating system developed by Google for mobile systems. It is based on the
Linux kernel and mainly designed for touchscreen devices such as tablets and smartphones.
The Android architecture is divided into four main layers and five sections. This is explained
using the given diagram –
Android Architecture:-
The architecture of an Android system consist of a software stack of different layers. Each
layer contains a group of various program components.
It is the chief component in the android architecture. The interaction of the hardware with the
software is provided by means of Linux. All the hardware drivers are handled by this kernel.
Drivers are the small programs written specifically to communicate with the hardware. The
lowest layer is the linux kernel,which is the closets to the hardware. It has all the major
hardware drivers such as display driver,camera driver,power management driver, and so
forth.
Example, the linux kernel has the camera driver. On installing the android os in a compatible
devices, the linux kernel will search the camera and then make it available to the system by
using camera driver.
Libraries:-
The layer next to the linux kernel layer is the android’s native libraries. This layer provides
the device,which has the capability to handle different types of data and information. This
libraries are coded in C and C++ languages for fast procedural transactions of data. A brief
description of some of the native android libraries is as follows:
1.WebKit:- Refers to the browser engine used to render and display HyperTextMarkup
Language(HTML) content.
2. Media Framework:- Refers to a library that handles the entire multi media feature by
deploying media codecs.
4.SQLite :- Refers to the Database engine Used in Android for Data Storage purposes.
Dalvik virtual machine and the Core Java Libraries are the part of Android Runtime
Environment. For Those who are familier with Java may realise that there is no Java Virtual
Machine(JVM). In android runtime, Dlavik virtual Machine is present instead of JVM.
Dalvik is a specialized virtual machine designed specifically for Android and optimized for
battery-powered mobile devices with limited memory and CPU.
It is used in Android system similar to the usage of JVMin Java. However, Dlavik Virtual
Machine is optimized for Low-Power Centeral Processing Unit(CPUs). And Low memory
modules. Unlike the JVM, the Dalvik Virtual Machine does not Recognise files with the
.class extension ;instead, it executes the files with the .dex extension. Infact, .dex files are
generated implicitly from the .class file and are highly optimized where memory and
processing power are constraints.
Advantages:
It is optimised for small platform where memory and processing power are
constraints.
It recognizes its exclusively designed APIs along with some useful APIs of Java.
At Times, many instances can be created simultaneously,giving benefit in the
security, isolation, memory management and multi threading.
These are the exclusively designed Java libraries for Android rather than Java SE and Java
ME libraries.However, most of the functionality of these libraries is similar to the java SE
libraries.
Application Framework:-
Application framework is of utmost importance for developer as the blocks inside this layer
directly communication with Android applications. The basic and much needed
functionalities such as resource management and voice call management are provided by this
layer.
Blocks
Telephony Manager:- Manages all Voice calls. This management can be considered as
optional. If your application is meant to use the voice calls,then telephony manager is used.
It is the Top layer in the android artictecture.This is the place where your application is
finally deployed over a device. Some applications are installed by default in a device, such as
SMS client app,dialer,Web browser, and contact manager.
Application Component
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 following four main components that can be used within an Android application −
1 Activities
They dictate the UI and handle the user interaction to the smart phone screen.
2 Services
They handle background processing associated with an application.
3 Broadcast Receivers
They handle communication between Android OS and applications.
4 Content Providers
They handle data and database management issues.
1.Activities
An activity represents a single screen with a user interface,in-short Activity performs actions
on the screen. 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 −
public class MainActivity extends Activity {
}
2.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.
3.Broadcast Receivers
Broadcast Receivers simply respond to broadcast messages from other applications or from
the system. For example, applications can also 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 broadcaster as an Intent object.
public class MyReceiver extends BroadcastReceiver {
public void onReceive(context,intent){}
}
4.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.
public class MyContentProvider extends ContentProvider {
public void onCreate(){}
}
We will go through these tags in detail while covering application components in individual
chapters.
Additional Components
There are additional components which will be used in the construction of above mentioned
entities, their logic, and wiring between them. These components are −
1 Fragments
Represents a portion of user interface in an Activity.
2 Views
UI elements that are drawn on-screen including buttons, lists forms etc.
3 Layouts
4 Intents
Messages wiring components together.
5 Resources
External elements, such as strings, constants and drawable pictures.
6 Manifest
Configuration file for the application.
Psion EPOC
The first recognisable apps came with Psion’s range of handheld computers – mostly PDAs –
that used the EPOC operating system. First released in the early 90s the sixteen-bit machines
(SIBO) which ran EPOC allowed users programmes such as a word processor, database,
spreadsheet and diary. Later models in the range, running a 32-bit OS, would come with up
to 2MB RAM and allow users to add additional apps via software packs (or via download if
you were lucky enough to own a modem).
EPOC, which was programmed in OPL (Open Programming Language) and allowed users to
create their own apps, would later form the backbone of the Symbian operating system.
Palm OS
Palm emerged as a major rival to Psion in the PDA market with its cheaper, lower
functionality range of PDAs – the Palm Pilot. Commercial success allowed Palm to release a
new generation of machines in 1996 which utilised the Palm OS. This had a touchscreen
GUI and came with a raft of basic apps as well as tons of third-party apps programmed in
C/C++. From Palm OS 3.0 onwards these included a WAP browser.
Following the acquisition of PalmSource by ACCESS, Palm OS became the ACCESS Linux
Platform before being abandoned in favour of webOS (which is now used in LG’s smart
TVs).
As mentioned earlier, Symbian grew out of the Psion EPOC operating system. Originally
developed by Symbian Ltd – a joint venture of Psion, Ericsson, Motorola and Nokia – the
operating system was almost ubiquitous. In 2009 250 million devices were running Symbian.
It was Nokia that really drove the development of Symbian OS. The S60 platform
was used on nearly all Nokia handsets as well as some Samsung and LG ones. The
use of different, fragmented platforms (Sony Ericsson and Motorola used UIQ and
there was MOAP(S) for NTT DoCoMo), each with its own API, meant that there
were a variety of deployment techniques and no standard market place for apps.
The incompatibility of apps across platforms and the failure to fully move to open source
(several key components were licensed from third parties) are probably what sounded the
death-knell for Symbian. There were also problems with malware, a browser which didn’t
support multiple windows or compress pages and a nightmare process for typing in non-
Latin text.
A market share of 37.6% in 2010 had dropped to 4.4% in 2012 after Nokia jumped ship for
the Windows Phone platform and other OEMs gathered beneath the banner of Android
with its single, unified market place for apps.
The last Symbian smartphone, the Nokia 808 PureView ran the Nokia Belle update which
used C++. It was an award-winning phone (chiefly because of its 41-megapixel camera) but
wasn’t enough to prolong Nokia’s heyday.
OHA member companies back the open platform concept for a number of reasons, as
follows:
Lower overall handset costs: Opens up resources, which facilitates the focus
on creating innovative applications, solutions and services.
The Android Platform was launched in 2007 by the Open Handset Alliance, an alliance of
prominent companies that includes Google, HTC, Motorola, Texas Instruments and others.
Although most of the applications that run on the Android Platform are written in Java, there
is no Java Virtual Machine. Instead, the Java classes are first compiled into what are known
as Dalvik Executables and run on the Dalvik Virtual Machine (DVM).
Android is an open development platform. However, it is not open in the sense that
everyone can contribute while a version is under development. This is all done behind
closed-doors at Google. Rather, the openness of Android starts when its source code is
released to the public after it is finalized. This means once it is released anyone interested
can take the code and alter it as they see fit.
To create an application for the platform, a developer requires the Android SDK, which
includes tools and APIs. To shorten development time, Android developers typically
integrate the SDK into graphical user IDEs (Integrated Development Environments).
Beginners can also make use of the App Inventor, an application for creating Android apps
that can be accessed online.
Android SDK
The Android SDK (Software Development Kit) is a set of development tools used to
develop applications for the Android platform that has become Apple’s biggest rival in the
smartphone space. The Android SDK includes the following:
Required libraries.
Debugger.
An emulator.
Relevant documentation for the Android Application Program Interfaces (APIs).
Sample source code.
Every time Google releases a new version of Android, a corresponding SDK is also released.
To be able to write programs with the latest features, developers must download and install
each version’s SDK for the particular phone. The SDK essentially represents Android’s
delivered toolkit for a specific version and technology of its operating systems.
The development platforms that are compatible with SDK include operating systems like
Windows (XP or later), Linux (any recent Linux distribution) and Mac OS X (10.4.9 or
later). The components of Android SDK can be downloaded separately. Third-party add-
ons are also available for download.
Although the SDK can be used to write Android programs in the command prompt, the most
common method is by using an integrated development environment (IDE).
apkanalyzer
Provides insight into the composition of your APK after the build process completes.
avdmanager
Allows you to create and manage Android Virtual Devices (AVDs) from the
command line.
lint
A code scanning tool that can help you to identify and correct problems with the structural
quality of your code.
retrace
For applications compiled by R8, retrace decodes an obfuscated stack trace that
maps back to your original source code.
sdkmanager
Allows you to view, install, update, and uninstall packages for the Android SDK.
Testing Android applications on emulator are sometimes faster and easier than doing on a real
device. For example, we can transfer data faster to the emulator than to a real device
connected through USB.
The Android emulator comes with predefined configurations for several Android phones,
Wear OS, tablet, Android TV devices.
Requirement and recommendations
The Android emulator takes additional requirements beyond the basic system requirement for
AndroidStudio. These requirements are given below:
o SDK Tools 26.1.1 or higher
o 64-bit processor
o Windows: CPU with UG (unrestricted guest) support
o HAXM 6.2.1 or later (recommended HAXM 7.2.0 or later)
https://developer.android.com/studio/run/emulator
―The circumstances that form the setting for an event, statement, or idea, and in terms of
which it can be fully understood‖
In android, context is the main important concept and the wrong usage of it leads to memory
leakage. Activity refers to an individual screen and Application refers to the whole app
and both extend the context class.
o Activity Context
The Overall view of the App hierarchy looks like the following
Application Tasks
A task is a collection of activities that users interact with when performing a certain job. The
activities are arranged in a stack—the back stack)—in the order in which each activity is
opened. For example, an email app might have one activity to show a list of new messages.
When the user selects a message, a new activity opens to view that message. This new activity is
added to the back stack. If the user presses the Back button, that new activity is finished and
popped off the stack. The following video provides a good overview of how the back stack
works.
When apps are running simultaneously in a multi-windowed environment, supported in
Android 7.0 (API level 24) and higher, the system manages tasks separately for each
window; each window may have multiple tasks. The same holds true for Android apps
running on Chromebooks: the system manages tasks, or groups of tasks, on a per-window
basis.
The device Home screen is the starting place for most tasks. When the user touches an icon
in the app launcher (or a shortcut on the Home screen), that app's task comes to the
foreground. If no task exists for the app (the app has not been used recently), then a new task
is created and the "main" activity for that app opens as the root activity in the stack.
When the current activity starts another, the new activity is pushed on the top of the stackand
takes focus. The previous activity remains in the stack, but is stopped. When an activity stops,
the system retains the current state of its user interface. When the user presses
the Back button, the current activity is popped from the top of the stack (the activity
isdestroyed) and the previous activity resumes (the previous state of its UI is
restored).Activities in the stack are never rearranged, only pushed and popped from the stack—
Figure 1. A representation of how each new activity in a task adds an item to the back stack.
When the user presses the Back button, the current activity is destroyed and the previous
activity resumes.
If the user continues to press Back, then each activity in the stack is popped off to reveal the
previous one, until the user returns to the Home screen (or to whichever activity was running
when the task began). When all activities are removed from the stack, the task no longer
exists.
An activity is the single screen in android. It is like window or frame of Java.By the help of
activity, you can place all your UI components or widgets in a single screen.The 7 lifecycle
method of Activity describes how activity will behave at different states.
onResume called when activity will start interacting with the user.
1. onCreate()
It is called when the activity is first created. This is where all the static work is done like
creating views, binding data to lists, etc. This method also provides a Bundle containing its
previous frozen state, if there was one.
2. onStart()
It is invoked when the activity is visible to the user. It is followed by onResume() if the
activity is invoked from the background. It is also invoked after onCreate() when the
activity is first started.
3. onRestart()
It is invoked after the activity has been stopped and prior to its starting stage and thus is
always followed by onStart() when any activity is revived from background to on-screen.
4. onResume()
It is invoked when the activity starts interacting with the user. At this point, the activity is at
the top of the activity stack, with a user interacting with it. Always followed by onPause()
when the activity goes into the background or is closed by the user.
5. onPause()
It is invoked when an activity is going into the background but has not yet been killed. It is
a counterpart to onResume(). When an activity is launched in front of another activity, this
callback will be invoked on the top activity (currently on screen). The activity, under the
7. onDestroy()
The final call received before the activity is destroyed. This can happen either because the
activity is finishing (when finish() is invoked) or because the system is temporarily
destroying this instance of the activity to save space. To distinguish between these
scenarios, check it with isFinishing() method.