0% found this document useful (0 votes)
17 views65 pages

Chapter One

The document provides an overview of Android, an open-source mobile operating system developed by Google, highlighting its architecture, features, and development ecosystem. It details the Android software stack, including the Linux kernel, native libraries, and application frameworks, as well as the core building blocks of Android applications such as activities, services, and intents. Additionally, it discusses the importance of Android as a platform for mobile app development due to its widespread usage and user-friendly interface.

Uploaded by

danifekadu72
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views65 pages

Chapter One

The document provides an overview of Android, an open-source mobile operating system developed by Google, highlighting its architecture, features, and development ecosystem. It details the Android software stack, including the Linux kernel, native libraries, and application frameworks, as well as the core building blocks of Android applications such as activities, services, and intents. Additionally, it discusses the importance of Android as a platform for mobile app development due to its widespread usage and user-friendly interface.

Uploaded by

danifekadu72
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 65

College of Computing and Informatics

Department of Information Technology

CHAPTER ONE
Introduction to
Mobile Development
s c)
D .(M 4
mu 02
le , 2
t : Ke c 20
I n s e: D e
t
Da
What is Android

Android is open-source software packages and Linux based operating system for mobile devices such
as tablet computers, smartphones and Television.
And also, it is a mobile operating system based on a modified version of the Linux kernel and other
open source software, designed primarily for touchscreen mobile devices such as smartphones and
tablets.
Hence, Android is developed by a consortium of developers known as the Open Handset
Alliance(OHA), with the main contributor and commercial marketer being google.
Therefore, it is developed by Google and later the OHA (Open Handset Alliance) which means a
consortium of 84 companies such as google, samsung, synaptics, Garmin, Teleca, Ebay, Intel etc.
The first beta version of the Android Software Development Kit (SDK) was released by Google in 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.
What is Android

Android is an operating system and programming platform developed by Google for mobile phones and
other mobile devices, such as tablets.
It can run on many different devices from many different manufacturers.
Android includes a software development kit (SDK) that helps to write original code and assemble
software modules to create apps for Android users.
Android also provides a marketplace to distribute apps. All together, Android represents an ecosystem
for mobile apps.
Android Features

The important features of android are given below:


1. It is open-source:- It refers to something people can modify and share because its design is
publicly accessible.
2. Anyone can customize the Android Platform:- anyone can inspect, modify, and enhance.
3. There are a lot of mobile applications that can be chosen by the consumer.
4. It provides many interesting features like weather details, opening screen, live RSS (Really
Simple Syndication) feeds etc.
Why develop apps for Android

Most popular platform for mobile apps

As the world's most popular mobile platform, Android powers hundreds of millions of mobile devices in
more than 190 countries around the world.

It has the largest installed base of any mobile platform and is still growing fast.

Every day another million users power up their Android-powered devices for the first time and start
looking for apps, games, and other digital content.
Why develop apps for Android

Best experience for app users

Android provides a touchscreen user interface (UI) for interacting with apps.

Android's UI is mainly based on direct manipulation.

People use touch gestures such as swiping, tapping, and pinching to manipulate on-screen objects.

In addition to the keyboard, there's a customizable on-screen keyboard for text input. Android can also support game
controllers and full-size physical keyboards connected by Bluetooth or USB.
Why develop apps for Android

It's easy to develop apps


To develop apps that take advantage of the Android operating system and UI, use the Android software
development kit (SDK).

The SDK includes software libraries of prewritten code, a debugger, a device emulator, documentation, sample
code, and tutorials.

Use the SDK to create apps that look great and take advantage of the hardware capabilities available on each
Android-powered device.

To develop apps using the SDK, use the Java programming language to develop the app and Extensible
Markup Language (XML) files to describe data resources. By writing the code in Java and creating a single
app binary, you create an app that can run on both phone and tablet form factors. You can declare your UI in
lightweight sets of XML resources.
Android Stack

Android architecture or Android software stack is categorized into five parts:


1. Linux kernel
2. Native libraries (middleware),
3. Android Runtime
4. Application Framework .
5. Application
Linux Kernel

• The Android operating system runs on top of the Linux kernel.


• The Linux kernel is the core of the Android OS, responsible for managing hardware resources,
providing drivers for various hardware components, and handling low-level system operations.
Here are some key points regarding the Android kernel:
1.Device Drivers: The kernel provides and manages device drivers for various hardware components
such as the CPU, GPU, display, camera, sensors, Wi-Fi, Bluetooth, and more. Device drivers enable
communication between the hardware and the operating system, allowing applications to interact with
the hardware effectively.
2.Memory Management: The kernel is responsible for managing system memory.
• This includes allocating and deallocating memory for running processes, implementing virtual
memory, and ensuring that different applications do not interfere with each other's memory space.
Linux Kernel

3. Process Management: The kernel oversees the creation, scheduling, and termination of processes
and threads. It allocates CPU time and resources to processes, ensuring that multiple applications can
run simultaneously without causing conflicts.
4. File System Operations: The kernel provides a file system interface that allows applications to read
from and write to storage devices, including internal storage and external SD cards. It also manages
file permissions and access control.
5. Security: The kernel enforces security policies, including user and group permissions. It ensures that
processes are isolated from each other and that sensitive data is protected. It also manages access to
hardware resources based on permissions and policies.
Linux Kernel

6. Power Management: The kernel is responsible for power management, including controlling the
CPU's power states and coordinating the use of power-saving features. It plays a critical role in
optimizing battery life on mobile devices.

7. Network Operations: The kernel handles network stack operations, including routing, packet
processing, and communication with network interfaces. It manages network sockets and
connections, allowing applications to communicate over the network.
8. I/O Operations: The kernel manages input and output operations for devices such as touchscreens,
keyboards, and external peripherals. It ensures that data from these devices is processed and made
available to applications.
Native Libraries

• Native libraries in the Android operating system play a critical role in enhancing performance,
providing hardware support, and enabling access to low-level system resources.
• These libraries are written in programming languages like C and C++ and are often utilized by the
Android system itself and Android app developers.
OpenGL ES Libraries: Android uses OpenGL for rendering graphics on the screen. The Android OS
includes native libraries for OpenGL ES (Embedded Systems), which are critical for 2D and 3D graphics
rendering.
Media Framework: Android has a comprehensive media framework that includes native libraries for
audio and video processing. These libraries enable tasks such as audio playback, video decoding, and
camera functionality.
Native Libraries

Hardware Abstraction Layer (HAL): Android relies on native libraries for hardware support through
the Hardware Abstraction Layer (HAL). Each hardware component, such as the camera, sensors, and
graphics hardware, has its HAL, allowing the Android system to interface with and control these
components.
SQLite: SQLite is a lightweight, embedded database engine used for managing and storing data on
Android devices. It provides native libraries for efficient database operations, making it suitable for many
Android applications that require local data storage.
Security Libraries: Android includes various security-related native libraries to implement features like
SSL/TLS for secure communications, cryptography, and secure boot mechanisms.
Wireless and Connectivity Libraries: Native libraries handle wireless communication, including Wi-Fi
and cellular network interactions. They also manage Bluetooth and other connectivity options.
Dalvik Virtual Machine

Dalvik was the runtime environment and virtual machine used by the Android operating system before
the transition to ART.
The DVM was responsible for executing Android applications (APK files).
• Dex Files: Android app code is written in Java and compiled into bytecode. In the case of Dalvik, this
bytecode is transformed into a specialized file format called Dalvik Executable (DEX) files. These
DEX files contain the bytecode instructions for the app.
• Just-In-Time Compilation (JIT): Dalvik used a just-in-time (JIT) compilation strategy. It converted
DEX bytecode into native machine code during app runtime. This allowed for improved execution
speed, as the native code could be executed more efficiently on the device's CPU.
DVM
Application Frameworks

In the Android operating system (OS) stack, application frameworks are an integral part of the
architecture that enables developers to build Android applications efficiently.
Activity Manager:
The Activity Manager framework manages the lifecycle of applications and user interface
components, known as Activities..
Window Manager:
The Window Manager framework is responsible for managing the device's display and handling
user interface windows. It determines the layout and positioning of application windows on the
screen and coordinates user input with the appropriate activities.
View System:
The View System framework provides the UI components (Views) that allow developers to create
user interfaces. It includes the View, ViewGroup, and Widget classes, enabling the construction of
interactive and responsive UIs.
Application Frameworks

Content Providers:
Content Providers allow applications to share data and access data from other apps.
They provide a structured way to interact with and manage data, including databases,
files, and other content.
Resource Manager:
The Resource Manager framework handles resources such as strings, images, layouts,
and other assets used by Android applications
Notification Manager:
The Notification Manager framework allows apps to display notifications to the user. It
manages notifications, including system-level notifications and those generated by apps.
Application Frameworks

Location Manager:
The Location Manager framework provides access to location-based services, allowing
applications to retrieve the device's location through GPS, Wi-Fi, or other location
providers.
Telephony Manager:
The Telephony Manager framework provides access to telephony-related information
and services, including network state, phone information, and telephony services like
making calls and sending SMS messages.
Package Installer:
The Package Installer framework is responsible for installing and updating Android
applications. It manages the installation process, including permissions and verification.
Application Frameworks

Media Framework:
The Media Framework provides tools and APIs for handling media-related tasks,
including audio and video playback, recording, and media streaming.
Sensors Framework:
The Sensors Framework gives access to various sensors built into Android devices, such
as accelerometers, gyroscopes, light sensors, and more. It allows apps to gather and
process sensor data.
Bluetooth Framework:
The Bluetooth Framework provides APIs for managing Bluetooth connectivity, enabling
the development of Bluetooth-enabled applications for tasks like pairing, data transfer,
and device communication.
Android Stack

Android architecture or Android software stack is categorized into five parts:


Android Stack

In the figure above:


1. Apps: Your apps live at this level, along with core system apps for email, SMS messaging, calendars,
internet browsing, and contacts.
2. Java API framework: All features for Android development, such as UI components, resource
management, and lifecycle management, are available through application programming interfaces
(APIs). You don't need to know the details of how the APIs work. You only need to learn how to use
them.
3. Libraries and Android runtime: Each app runs in its own process, with its own instance of the
Android runtime. Android includes a set of core runtime libraries that provide most of the
functionality of the Java programming language. Many core Android system components and
services are built from native code that require native libraries written in C and C++. These native
libraries are available to apps through the Java API framework.
Android Stack

In the figure above:


4. Hardware abstraction layer (HAL): This layer provides standard interfaces that expose device
hardware capabilities to the higher-level Java API framework. The HAL consists of multiple library
modules, each of which implements an interface for a specific type of hardware component, such as the
camera or Bluetooth module.
5. Linux kernel: The foundation of the Android platform is the Linux kernel. The layers above the
Linux kernel rely on the Linux kernel for threading, low-level memory management, and other
underlying functionality. Using a Linux kernel enables Android to take advantage of Linux-based
security features and allows device manufacturers to develop hardware drivers for a well-known kernel.
DVM
Android Version

I
Android Version
Android Version
Android Core Building Blocks

The core building blocks or fundamental components of android are:- activities, views,
intents, services, content providers, fragments and AndroidManifest.xml.
The basic components of any android application are as follows:

1. Activities 8. SQLite Database

2. Services 9. SharedPreferences

3. Broadcast Receivers 10. Resources


4. Content Providers 11. Notifications
5. Intents
6. Fragments
7. Views
1.Activities:
• Activities are the basic unit of interaction in an Android application.
• They represent individual screens or UI components that users can interact with.
• Each screen of an app is typically implemented as an activity.
• An activity is one screen of an app. In that way the activity is very similar to a
window in the Windows operating system.
• The most specific block of the user interface is the activity. An Android app
contains activities, meaning one or more screens.
• Examples: Login screen, sign up screen, and home screen.
• An activity class is per definition a class in Android. Every application which has
UI must inherit it to create a window.
How does an activity works

• An activity in Android is a specific combination of XML files and JAVA files.


• XML files provide the design of the screen and JAVA files deal with all coding stuff like
handles, what is happening, design files, etc.
• JAVA files and XML files make our activity complete.
Activity Lifecycle

• An activity goes through a number of states. Activity lifecycle in Android manages the
different states of activity, such as when the activity starts or stops, etc. All of these states
are managed by callback methods.
Activity life cycle

An activity has essentially four states:

onCreate(): Called when the activity is first created. This is where you should do all of your
normal static set up: create views, bind data to lists, etc. This method also provides you with
a Bundle containing the activity's previously frozen state, if there was one. Always
followed by onStart().
Activity life cycle

onStart: Called when the activity is becoming visible to the user. Followed by onResume()
if the activity comes to the foreground, or onStop() if it becomes hidden.

onReStart: Called after your activity has been stopped, prior to it being started again.
Always followed by onStart().
Activity life cycle
onResume: Called when the activity will start interacting with the user. At this point your
activity is at the top of its activity stack, with user input going to it. Always followed by
onPause().

onPause(): Called when the activity loses foreground state, is no longer focusable or before
transition to stopped/hidden or destroyed state.Followed by either onResume() if the
activity returns back to the front, or onStop() if it becomes invisible to the user.
Activity life cycle

onStop: Called when the activity is no longer visible to the user. This may happen either
because a new activity is being started on top, an existing one is being brought in front of
this one, or this one is being destroyed. This is typically used to stop animations and
refreshing the UI, etc.

onDestroy: The final call you receive before your activity is destroyed. This can happen
either because the activity is finishing
Activity life cycle
2. Services

• A service in application component that can perform long-running operations in the


background.
• It does not provide a user interface. Once started, a service might continue running
for some time, even after the user switches to another application.
• Services are background processes that perform tasks without a user interface.
• They can be used for long-running operations such as handling network requests,
playing music, or monitoring sensors.
• Services run independently of the application's UI.
Service

A service is a component which runs in the background without direct interaction with the
user.
Android service is a component that is used to perform operations on the background such
as playing music, handle network transactions, interacting content providers etc.
As the service has no user interface, it is not bound to the lifecycle of an activity.
They handle background processing associated with an application.
There are two types of services local and remote.
Local service is accessed from within the application whereas remote service accessed
remotely from other applications running on the same device.
Type of Services

There are three types of Services


1. Foreground Services
2. Background Services
3. Bound Services
1. A foreground service performs some operation that is noticeable to the user. For example, an audio
app would use a foreground service to play an audio track. Foreground services must display a
notification. Foreground services continue running even when the user isn't interacting with the app.
2. A background service performs an operation that isn't directly noticed by the user. For example, if an
app used a service to compact its storage, that would usually be a background service.
3. A service is bound when an application component binds to it by calling bindService(). A bound
service offers a client-server interface that allows components to interact with the service, send
requests, receive results, and even do so across processes with interprocess communication (IPC).
Type of Services

There can be two forms of a service.


The lifecycle of service can follow two different paths: started or bound.
1. Started
2. Bound
1) Started Service
A service is started when an application component, such as an activity, starts it by calling
startService().
Once started, a service can run in the background indefinitely, even if the component that
started it is destroyed.
This service is also known as Un Bounded Service.
It is stopped by stopService() method.
The service can stop itself by calling the stopSelf() method.
Type of Services

Bound Service
A service is bound when an application component binds to it by calling bindService().
A bound service offers a client-server interface that allows components to interact with the
service, send requests, get results, and even do so across processes with inter-process
communication (IPC).
The client can unbind the service by calling the unbindService() method.
The service cannot be stopped until all clients unbind the service.
Services life cycle

• A service has life cycle callback methods that


you can implement to monitor changes in the
service's state and you can perform work at
the appropriate stage.

• The following diagram on the left shows the


life cycle when the service is created with
startService() and the diagram on the right
shows the life cycle when the service is
created with bindService()
3. Broadcast Receivers:
• They handle communication between Android OS and applications. Now create the
service implementation class by inheriting the Service class and overriding its
callback methods.

• Broadcast receivers are components that listen for system-wide or application-


specific events or broadcasts.
• When an event occurs, a broadcast receiver can trigger actions within an app or
notify the user.
• Common use cases include responding to system events like low battery or
incoming SMS messages.
4. Content Providers:
• Content Providers are used to share data between the applications. Such requests,
handled by the methods of the ContentResolver class.
• They allow apps to securely share structured data, such as databases, and provide a
consistent way to interact with data stored on the device, including contacts,
calendar events, and media files.
5. Intents:
• Intents are messages that allow different components of an Android application or
between different applications to request actions or communication.
• They can be explicit (targeting a specific component within the app) or implicit
(allowing any app that can handle the intent to respond).
6. Fragments:
• Fragments are reusable UI components that can be used within an activity to create
flexible and modular user interfaces.
• They are often used to create multi-pane layouts for tablets or for constructing
dynamic user interfaces.
7. Layouts and Views:
• Layouts are used to define the structure of the user interface, and views are the UI
components themselves, such as buttons, text fields, and images.
• Layouts and views are used to create the visual elements of an Android application.
• The view is everything we can see on the screen of the app — think of the individual
UI elements like buttons, labels, and text fields.
8. Resources:
• Resources are external assets used by Android applications, including images,
layouts, strings, and XML files.
• They allow for easy localization and customization of an app without modifying the
source code.
9. SharedPreferences:
• SharedPreferences allow apps to store and retrieve small amounts of data in key-
value pairs. This is often used for storing app settings and preferences.
10. SQLite Database:
• Android includes SQLite, a lightweight relational database management system,
which is used for storing structured data in a local database on the device.
• It is commonly used for data persistence in Android apps.
11. Notifications:
• The notification system allows apps to alert the user with messages and updates
even when the app is not in the foreground.
• Notifications can include text, images, and actions.
Broadcast Service

Fragment
Fragments are like parts of activity. An activity can display one or more fragments on the
screen at the same time.

AndroidManifest.xml
It contains informations about activities, content providers, permissions etc. It is like the
web.xml file in Java EE.
Android Software Development kit(SDK)

• A software development kit (SDK) is a set of programs used by a computer software


programmer to write and develop application programs.
• Typically, an SDK includes a visual screen builder, an editor, a compiler, a linker, and
sometimes other facilities.
• Software development kit is a programming package that enables a developer or
programmer to develop mobile applications for a specific mobile platform.
• The Android SDK includes some library with source code, development tools, an
emulator, and required libraries to build Android applications.
• Software development kit is support all professional languages.
• Applications are written for source code using the Java programming language and run
on Dalvik virtual machine (DVM), a custom virtual machine designed for embedded use
which runs on top of a Linux kernel.
Java Packages

A java package is a group of similar types of classes, interfaces and sub-packages.


A package in Java is used to group related classes.
Think of it as a folder in a file directory.
We use packages to avoid name conflicts, and to write a better maintainable code
Package in java can be categorized in two form:
• built-in package and
• user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
Android Virtual Device (AVD)

• It is used to test the android application without the need for mobile or tablet etc. It can
be created in different configurations to emulate different types of real devices.

• The Android emulator is an Android Virtual Device (AVD), which represents a


specific Android device.

• Android Emulator -A virtual mobile device that runs on our computer -use to design,
debug, and test our applications in an actual Android run-time environment.

• The Android emulator provides almost all the functionality of a real device.
Installing the emulator

The Android emulator is installed while installing the Android Studio. However some
components of emulator may or may not be installed while installing Android Studio.

To install the emulator component, select the Android Emulator component in the SDK
Tools tab of the SDK Manager or click by AVD manager in the icon.
Dalvik Virtual Machine (DVM)

The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for mobile
devices. It optimizes the virtual machine for memory, battery life and performance.
Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
The Dex compiler converts the class files into the .dex file that run on the Dalvik VM.
Multiple class files are converted into one dex file.
Android Application
Anatomy of Android Application

Before you run your app, you should be aware of a few directories and files in the
Android project.
AndroidManifest.xml
This is the manifest file which describes the fundamental characteristics of the app
and defines each of its components.
Java
This 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.

res/drawable-hdpi

This is a directory for drawable objects that are designed for high-density screens.
Anatomy of Android Application

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 colours definitions.

Build.gradle

This is an auto generated file which contains compileSdkVersion, buildToolsVersion,


applicationId, minSdkVersion, targetSdkVersion, versionCode and versionName
The Main Activity File

The main activity code is a Java file MainActivity.java.

This is the actual application file which ultimately gets converted to a Dalvik executable and runs your
application.

Following is the default code generated by the application wizard for Hello World! Application

Here, R.layout.activity_main refers to the activity_main.xml file located in the res/layout


folder. The onCreate() method is one of many methods that are figured when an activity is
loaded.
The Manifest File

Whatever component we want develop as a part of our application, we must declare all its
components in a manifest.xml which resides at the root of the application project directory.
This file works as an interface between Android OS and your application, so if we do not
declare your component in this file, then it will not be considered by the OS.

For example, a default manifest file will look like as following file
The Manifest File
The Manifest File

Here <application>...</application> tags enclosed the components related to the application.


Attribute android:icon will point to the application icon available under res/drawable-hdpi.
The application uses the image named ic_launcher.png located in the drawable folders

The <activity> tag is used to specify an activity and android:name attribute specifies the
fully qualified class name of the Activity subclass and the android:label attributes specifies a
string to use as the label for the activity. You can specify multiple activities using <activity>
tags.
The Manifest File

The action for the intent filter is named android.intent.action.MAIN to indicate that this
activity serves as the entry point for the application.
The category for the intent-filter is named android.intent.category.LAUNCHER to indicate
that the application can be launched from the device's launcher icon.

The @string refers to the strings.xml file explained below. Hence, @string/app_name refers
to the app_name string defined in the strings.xml file, which is "HelloWorld". Similar way,
other strings get populated in the application.
The Color File

The strings.xml file is located in the res/values folder and it contains all the text that our
application uses. A string is a simple resource that is referenced using the value provided in
the name attribute (not the name of the XML file). So, we can combine string resources
with other simple resources in the one XML file, under one <resources> element.

Elements:

<resources>
Required. This must be the root node.
No attributes.
<string>
A string, which can include styling tags. Beware that must escape
apostrophes and quotation marks.
attributes:
name
String. A name for the string. This name is used as the resource ID.
The Color File

A color value defined in XML. The color is specified with an RGB value and alpha channel.
We can use a color resource any place that accepts a hexadecimal color value. And also, we
can use a color resource when a drawable resource is expected in XML (for example,
android:drawable="@color/green").
The value always begins with a pound (#) character and then followed by the Alpha-
Red-Green-Blue information in one of the following formats:
#RGB
#ARGB
#RRGGBB
#AARRGGBB
The Color File
<color>
A color expressed in hexadecimal, as described above.
attributes:
name

String. A name for the color. This will be used as the resource ID.
example:
XML file saved at res/values/colors.xml:
The Layout File

The activity_main.xml is a layout file available in res/layout directory, that is referenced by


our application when building its interface. We’ll modify this file very frequently to change
the layout of our application. For our "Hello World!" application, this file will have
following content related to default layout :
Question??????????

You might also like