Nothing Special   »   [go: up one dir, main page]

Unit 1 Introduction of Android

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Unit 1 Introduction of Android

1. Android Operating System

2. History of Mobile Software Development

3. Open Handset Alliance (OHA)

4. The Android Platform

5. Installation

6. Android SDK

7. Command Line Tools and the Android Emulator

8. Application Context

9. Application Tasks

1. Android Operating System

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 –

The Android - Operating System

o Android is an Operating System.


o It is not a hardware platform.
o Android includes a Linux kernel-based OS.
o Android OS are written in C or C++.
o We can develop User applications using JAVA.
o It is called as APK (Android Application Package).

Unit-1 Introduction of Android Page 1


 Android is released under two different open source licenses.
 The Linux kernel is released under the GPL (GNU General Public License), as is
required for anyone licensing the open source OS kernel.
 The Android platform, excluding the kernel, is licensed under the Apache Software
License (ASL).
 While both licensing models are open source–oriented.
 Let's See Android versions...

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.

Unit-1 Introduction of Android Page 2


Linux Kernel:-

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.

3.Surface Manager:-Refers to the Manipulations Performed on the screen of the device. To


do so , Window Manager is combine with of screen buffering.

4.SQLite :- Refers to the Database engine Used in Android for Data Storage purposes.

5. OpenGL:-Refers to as a Rendering engine, which is used to render Graphics to the screen.

Unit-1 Introduction of Android Page 3


Android Runtime:-

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.

Dalvik Virtual Machine:-

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.

Core Java Libraries:-

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

Activity Manager:- Manages the activity life cycle of applications.

Content Providers:-provide data sharing between applications.

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.

Location Manager:-Manages the activities related with location in your application.

Resource Manager:- Manages the different kinds of resources in an application.

Unit-1 Introduction of Android Page 4


Application

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 −

Sr.No Components & Description

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.

Unit-1 Introduction of Android Page 5


A service is implemented as a subclass of Service class as follows −
public class MyService extends Service {
}

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 −

S.No Components & Description

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

Unit-1 Introduction of Android Page 6


View hierarchies that control screen format and appearance of the views.

4 Intents
Messages wiring components together.

5 Resources
External elements, such as strings, constants and drawable pictures.

6 Manifest
Configuration file for the application.

Features of Android Operating System


The unique features/characteristics of the android operating system include the following.
 Near Field Communication (NFC)
 Alternate Keyboards
 IR Transmission
 No-Touch Control
 Automation
 Wireless App Downloads
 Storage & Battery Swap
 Custom Home Screen
 Widgets
 Custom ROMs
 Headset layout
 Storage
 Connectivity: GSM/EDGE, IDEN, CDMA, Bluetooth, WI-FI, EDGE,3G,NFC, LTE,GPS.
 Messaging: SMS, MMS, C2DM (could to device messaging), GCM (Google could
messaging)
 Multilanguage support
 Multi-touch
 Video calling
 Screen capture
 External storage
 Streaming media support
 Optimized graphics

What is a Mobile Application?


A mobile application (or mobile app) is a software application designed to run
on smartphones, tablet computers and other mobile devices.
The history of the mobile app begins, obviously, with the history of the mobile device and
the first mobile phones whose microchips required the most basic of software to send and
receive voice calls. But since then, things have got a lot more complicated.

Unit-1 Introduction of Android Page 7


Where did it all begin?
The first public cellular phone call was made by Martin Cooper of Motorola on 3rd April
1973 in a publicity stunt in New York. There would be another ten years of R&D however
before the first cell phone would hit the market. The DynaTAC 8000X weighed in at around
2 pounds, cost $4,000 and didn’t run any apps.

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

Unit-1 Introduction of Android Page 8


Symbian

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.

Open Handset Alliance (OHA)


What does Open Handset Alliance (OHA) mean?
The Open Handset Alliance (OHA) is a business alliance that was created for the purpose
of developing open mobile device standards. The OHA has approximately 80 member
companies, including HTC, Dell, Intel, Motorola, Qualcomm and Google. The OHA's main
product is the Android platform - the world's most popular smartphone platform.
OHA members are primarily mobile operators, handset manufacturers, software development
firms, semiconductor companies and commercialization companies. Members share a
commitment to expanding the commercial viability of open platform development.

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.

Unit-1 Introduction of Android Page 9


Developer-friendly environment: In the open-source community, developers share
notes to expedite application development.

Post-development: Provides an ideal channel for application marketing and


distribution.

The Android Platform


The Android platform is a platform for mobile devices that uses a modified Linux kernel. The Android
Platform was introduced by the Open Handset Alliance in November of 2007. Most applications that
run on the Android platform are written in the Java programming language.

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

Unit-1 Introduction of Android Page 10


The recommended IDE is Eclipse with the Android Development Tools (ADT) plug-in.
However, other IDEs, such as NetBeans or IntelliJ, will also work.
Most of these IDEs provide a graphical interface enabling developers to perform
development tasks faster. Since Android applications are written in Java code, a user should
have the Java Development Kit (JDK) installed.

Command Line Tools and the Android Emulator


The Android SDK is composed of multiple packages that are required for app
development. This page lists the most important command line tools that are available,
organized by the packages in which they're delivered.
You can install and update each package using Android Studio's SDK Manager or the
sdkmanager command line tool. All of the packages are downloaded into your Android SDK
directory, which you can locate as follows:
1. In Android Studio, click File > Project Structure.
2. Select SDK Location in the left pane. The path is shown under Android SDK location.
Located in: android_sdk/cmdline-tools/version/bin/

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.

How to Install Android SDK Tools on Windows


https://android.tutorials24x7.com/blog/how-to-install-android-sdk-tools-on-window

Unit-1 Introduction of Android Page 11


Android Emulator
The Android emulator is an Android Virtual Device (AVD), which represents a specific
Android device. We can use the Android emulator as a target device to execute and test our
Android application on our PC. The Android emulator provides almost all the functionality of
a real device. We can get the incoming phone calls and text messages. It also gives the
location of the device and simulates different network speeds. Android emulator simulates
rotation and other hardware sensors. It accesses the Google Play store, and much more

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

Unit-1 Introduction of Android Page 12


Application Context
Android apps are popular for a long time and it is evolving to a greater level as user’s
expectations are that they need to view the data that they want in an easier smoother view.
Hence, the android developers must know the important terminologies before developing the
app. In Android Programming we generally come across a word context. So what exactly is
this context and why is it so important? To answer this question lets first see what the literal
meaning of context is:

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

Types of Context in Android


There are mainly two types of context are available in Android.
o Application Context and

o Activity Context
The Overall view of the App hierarchy looks like the following

Unit-1 Introduction of Android Page 13


o It can be seen in the above image that in “Sample Application”, nearest Context is
Application Context. In “Activity1” and “Activity2”, both Activity Context (Here it
is Activity1 Context for Activity1 and Activity2 Context for Activity2) and
Application Context. The nearest Context to both is their Activity Context only.
Application Context
o This context is tied to the life cycle of an application. Mainly it is an instance (object)
that is a singleton and can be accessed via getApplicationContext(). Some use cases
of Application Context are:
If it is necessary to create a singleton object
During the necessity of a library in an activity
o getApplicationContext():
o It is used to return the context which is linked to the Application which holds all
activities running inside it. When we call a method or a constructor, we often have to pass a
context and often we use “this” to pass the activity context or “getApplicationContext” to
pass the application context. This method is generally used for the application level and can
be used to refer to all the activities. For example, if we want to access a variable throughout
the android app, one has to use it via getApplicationContext().

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—

Unit-1 Introduction of Android Page 14


pushedonto the stack when started by the current activity and popped off when the user leaves
it using the Back button. As such, the back stack operates as a "last in, first out" object structure.
Figure 1 visualizes this behaviour with a timeline showing the progress between
activitiesalong with the current back stack at each point in time.

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.

Android Activity Lifecycle

Android Activity Lifecycle is controlled by 7 methods of android.app.Activity class. The


android Activity is the subclass of ContextThemeWrapper class.

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.

Unit-1 Introduction of Android Page 15


Android Activity Lifecycle methods

Let's see the 7 lifecycle methods of android activity.


Method Description

onCreate called when activity is first created.

onStart called when activity is becoming visible to the user.

onResume called when activity will start interacting with the user.

onPause called when activity is not visible to the user.

onStop called when activity is no longer visible to the user.

onRestart called after your activity is stopped, prior to start.

onDestroy called before the activity is destroyed.

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

Unit-1 Introduction of Android Page 16


active activity, will not be created until the active activity’s onPause() returns, so it is
recommended that heavy processing should not be done in this part.
6. onStop()
It is invoked when the activity is not visible to the user. It is followed by onRestart() when
the activity is revoked from the background, followed by onDestroy() when the activity is
closed or finished, and nothing when the activity remains on the background only. Note that
this method may never be called, in low memory situations where the system does not have
enough memory to keep the activity’s process running after its onPause() method is called.

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.

Unit-1 Introduction of Android Page 17


Unit-1 Introduction of Android Page 18
Unit-1 Introduction of Android Page 19
Unit-1 Introduction of Android Page 20

You might also like