Unit 2
Unit 2
2.0 Introduction
2.1 Objectives
2.2Android Architecture
2.2.1Check Your Progress
2.2.2Video V3: Android Architecture
2.2.3 Check Your Progress
2.3 Types of mobile applications
2.3.1Check Your Progress
2.4 Application Fundamentals
2.5 Summary
2.6Further Readings
2.0 INTRODUCTION
This unit gives you an overview of the basic internal architecture of Android. The first
part of this unit focuses on the Android architecture and the application framework,
which developers can leverage in developing Android applications. Later it discusses
different types of mobile applications with their pros and cons. This unit has one video
that you need to watch and three activities to complete.
2.1 OBJECTIVES
19
Android Architecture
2.2 ANDROID ARCHITECTURE
As you can see in the Figure 2.1 that Android Architecture (also called Software
Stack) has the following layers:
Linux Kernel
Hardware Abstraction Layer (HAL)
Native Libraries
Android Run Time
Android Application Framework
Application Layer
Linux Kernel
Android is designed on the top of Linux Kernel which is an open source operating
system as explained in the previous unit.
20
Linux Kernel never really interacts with the users and developers, but is at the heart of Features of Android
the whole system. Its importance stems from the fact that it provides the following
functions in the Android system:
Hardware abstraction
Memory management programs
Security settings
Power management software
Other hardware drivers (Drivers are programs that control hardware devices.)
Support for shared libraries
Network stack
In this section we have learned how Linux is involved with Android. Now you need to
complete the given activity before reading further in this unit.
(Source: https://source.android.com/source/index.html)
Native Libraries
Native libraries run over the HAL and it consist various C / C++ library like libc. It
also includes following standard libraries:
The following Figure 2.4 shows the Android library layer and its components.
(Source: http://androidfulcrum.blogspot.com/2014/02/what-is-android-architecture.html)
Libraries carry a set of instructions to guide the device in handling different types of
data. For instance, the playback and recording of various audio and video formats is
guided by the Media Framework Library. This layer enables the device to handle
different types of data with the use of these libraries.
(Source:http://androidfulcrum.blogspot.com/2014/02/what-is-android-architecture.html)
ART is the successor of Dalvik Virtual machine. ART is the managed runtime system
that helps to run applications and system services. ART and its predecessor Dalvik
were originally created specifically for the Android project. ART is compatible with
DVM, so it helps to run Dalvik Executable codes. For devices running Android
22
version 5.0 (API level 21) or higher, each app runs in its own process and with its own Features of Android
instance of the Android Runtime (ART)ART has the following features:
Core Libraries
Core libraries are the collection of Android specific core java libraries. You will be
using these libraries when writing your Android applications in later units.
URL: https://tinyurl.com/ya7t24et
Application Layer
Figure 2.6 shows the application layer which is the top layer of Android architecture.
Every application (e.g. Contacts, Browsers, etc.), whether it is a native application or a
third party application, runs in Application layer. Preinstalled applications provided by
the vendors are called native apps and applications developed by another developer
are called third party applications. In application layer, third party apps can replace the
native apps. This is the beauty of Android.
(Source: http://androidfulcrum.blogspot.com/2014/02/what-is-android-architecture.html)
23
Android Architecture
2.3 TYPES OF MOBILE APPLICATIONS
It is obvious that mobile technologies have been evolving rapidly in recent years, with
a huge amount of creativity on mobile application development. As a result, there are
more prominent needs than at any other time for a mobile application client platform
which can not only deliver mobile-optimized user experience, but also support the
increasingly complex business logic that the application must support.
It is important to consider various factors related to the purpose of the developing the
app when deciding between which types of app you should build. Therefore, it is
important to check your current priorities and where you want to be in the future
before selecting the app. The quality of the user experience you need your app to have,
the complexity of the features you need for your app to work and the budget, helps
you choose which approach is best.
Today, we often speak of three types of mobile applications according to how they are
developed: native, web and hybrid. Further explanations on these types are given
below.
Native apps
Those that are fully programmed in the development environment specific to each
operating system.
Native applications can leverage the full array of features and functions available
through the mobile device’s core operating system. Generally, they are fasterand offer
a significantly usable interface than the others.
Advantages:
Smooth performance
Good user experience
App icon available on the device
Can receive push notifications
Runs inside the operating system
Can use the platform APIs
Disadvantages:
Web apps
Fully developed in HTML 5, Mobile Web apps offer an attractive option for
companies that do not want to invest in building native applications across four
different mobile platforms. Whether getting a new application up and running or
maintaining or updating an existing mobile solution with Mobile Web Apps is simple
and inexpensive. Better yet, HTML5-driven mobile Web apps are cross-platform
compatible and, more secure than native applications (given that very little data is
stored locally on the native device.)
24
Advantages: Features of Android
Cross platform
Single code base
Fast to production
Lower development cost
Disadvantages:
Sluggish performance
Require loading
Network connection required
Not available in the app stores
Extremely limited API access Lives in the browser
Hybrid apps
Apps developed partly with the native development environment and partly in WEB
language (HTML 5).
Today, technology changes so rapidly that most businesses require immense flexibility
and scalability to adapt content, design and even application architecture. By
deploying applications that rely on a robust combination of HTML5 Web technologies
and native operating system features, you preserve a large degree of control over the
content and design of the solutions we build for mobile platforms.
Many companies find that this hybrid development process empowers them to
perform fast, easy, on-demand updates, without losing the inherent advantages that
come from hosting a solution in the iTunes Apps Store or the Android Marketplace.
Advantages:
Disadvantages:
Each has its positives and negatives that can and should influence the decision when
making a choice for development. Which is most appropriate will vary based on your
25
Android Architecture particular requirements. The Table 2.1 shows a summary of the features discussed in
each type.
Android apps are written in the Java programming language. The Android SDK tools
compile your codealong with any data and resource filesinto an APK: an Android
package, which is an archive file with an .apk suffix. One APK file contains all the
contents of an Android app and this is the file that Android-powered devices use to
install the app.
Once installed on a device, each Android app lives in its own security
sandbox
The Android operating system is a multi-user Linux system in which each app
is a different user.
By default, the system assigns each app a unique Linux user ID (the ID is
used only by the system and is unknown to the app). The system sets permissions for
all the files in an app so that only the user ID assigned to that app can access them.
Each process has its own virtual machine (VM), so an app's code runs in
isolation from other apps.
By default, every app runs in its own Linux process. Android starts the
process when any of the app's components need to be executed, then shuts down the
26
process when it's no longer needed or when the system must recover memory for other Features of Android
apps.
In this way, the Android system implements the principle of least privilege. That is,
each app, by default, has access only to the components that it requires to do its work
and no more. This creates a very secure environment in which an app cannot access
parts of the system for which it is not given permission.
However, there are ways for an app to share data with other apps and for an app to
access system services:
It's possible to arrange for two apps to share the same Linux user ID, in which
case they are able to access each other's files. To conserve system resources, apps with
the same user ID can also arrange to run in the same Linux process and share the same
VM (the apps must also be signed with the same certificate).
An app can request permission to access device data such as the user's
contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and
more. The user has to explicitly grant these permissions.
That covers the basics regarding how an Android app exists within the system.
App components are the essential building blocks of an Android app. Each component
is a different point through which the system can enter your app.
Not all components are actual entry points for the user and some depend on each
other, but each one exists as its own entity and plays a specific role—each one is a
unique building block that helps define your app's overall behaviour.
There are four different types of app components. Each type serves a distinct purpose
and has a distinct lifecycle that defines how the component is created and
destroyed.Here are the four types of application components. These four components
are further explained in unit 5.
Activities
An activity represents a single screen with a user interface. For example, an email app
might have one activity that shows a list of new emails, another activity to compose an
email, and another activity for reading emails. Although the activities work together to
form a cohesive user experience in the email app, each one is independent of the
others. As such, a different app can start any one of these activities (if the email app
allows it). For example, a camera app can start the activity in the email app that
composes new mail, in order for the user to share a picture.
An activity is implemented as a subclass of Activity and you can learn more about
activity lifecycle in the next unit.
27
Android Architecture Services
A service is a component that runs in the background to perform long-running
operations or to perform work for remote processes. A service does not provide a user
interface. For example, a service might play music in the background while the user is
in a different app, or it might fetch data over the network without blocking user
interaction with an activity. Another component, such as an activity, can start the
service and let it run or bind to it in order to interact with it.
A service is implemented as a subclass of Service and you can learn more about it in
the Services developer guide.
Content providers
A content provider manages a shared set of app data. You can store the data in the file
system, SQLite database, on the web, or any other persistent storage location your app
can access. Through the content provider, other apps can query or even modify the
data (if the content provider allows it). For example, the Android system provides a
content provider that manages the user's contact information. As such, any app with
the proper permissions can query part of the content provider (such as contact data) to
read and write information about a particular person.
Content providers are also useful for reading and writing data that is private to your
app and not shared. For example, the Note Pad sample app uses a content provider to
save notes.
Broadcast receivers
A broadcast receiver is a component that responds to system-wide broadcast
announcements. Many broadcasts originate from the system—for example, a
broadcast announcing that the screen has turned off, the battery is low, or a picture
was captured. Apps can also initiate broadcasts—for example, to let other apps know
that some data has been downloaded to the device and is available for them to use.
Although broadcast receivers don't display a user interface, they may create a status
bar notification to alert the user when a broadcast event occurs. More commonly,
though, a broadcast receiver is just a "gateway" to other components and is intended to
do a very minimal amount of work. For instance, it might initiate a service to perform
some work based on the event.
2.5 SUMMARY
28
Features of Android
2.6 FURTEHR READINGS
https://source.android.com/devices/ (CC-BY)
http://androidfulcrum.blogspot.com/2014/02/what-is-android-architecture.html (CC-
BY)
https://source.android.com/source/index.html (CC-BY)
29