Introduction To Android
Introduction To Android
Introduction to Android
Chapter 1
1. Introduction to Android
Topics Covered
▪ Overview for Android
▪ Definition of Android
▪ Why Android
▪ History of Android
▪ Features of Android
▪ Android Architecture
▪ Environment Setup
▪ Installing Android Studio
▪ Test AVD(Android Virtual Device)
▪ Create “Hello Android World”
▪ Android Core Building Blocks
▪ Android Project Structure
What is Android?
The Android platform provides a framework API that applications can use to
interact with the underlying Android system.
❖ A set of XML elements and attributes for declaring and accessing resources
❖ A set of Intents
Make Apps that can help you in every aspect of your life, can help
you communicate, organize, educate, entertain or just to make
your life easier in every device that they might run on!.
It is open source.
Google has made the code for all the low-level "stuff" as well as the
needed middleware to power and use an electronic device, and
gave Android freely to anyone who wants to write code and build the
operating system from it.
❖ The next table shows the different Android Versions and their
corresponding Api level
Version Code Name API Level
1.5 Cupcake 3
1.6 Donut 4
2.0-2.1 Eclair 5-7
2.2.x Froyo 8
2.3-2.3.4 Gingerbread 9-10
3.0-3.2 Honeycomb 11-13
4.0-4.0.4 Ice Cream Sandwich 14–15
4.1-4.3 Jelly Bean 16–18
4.4 KitKat 19–20
5.0–5.1 Lollipop 21-22
6.0 Marshmallow 23
7.0 Nougat 24
7.1-7.1.2 Nougat 25
8.0 Oreo 26
8.1 Oreo 27
9 Pie 28
10 Q 29
11 R 30
Features of Android
Beautiful UI
Connectivity
Along with some standard and basic network connectivity, Android provides Bluetooth,
Wi-Fi, NFC, P2P, SIP and USB to interact and connect with other devices and WiMAX.
Storage
Wi-Fi Direct
This technology is used to connect devices directly to each other via Wi-Fi without an
intermediate access point
Cont’d
Messaging
Android OS provides SMS (Short Message Service) and MMS (Multimedia Messaging
Service) to send short text messages, videos, photos or audios to other devices.
Multi-tasking
This operating system comes with a feature of Multi-tasking so that the users can use
multiple applications simultaneously at the same time.
Android Beam
With the Android Beam file transfer feature you can share small or large files to other
devices. This is a NFC-based technology with lets you share files just by touching the two
NFC-enabled devices together.
With FCM you can send notification messages or data messages, send messages from
client apps and distribute messages to your client app to single devices/ to groups of
devices.
Android Architecture
First, Let we discuss about Operating System
Operating System: The most visible part of Android, at least for developers,
is its operating system.
➢ it stands between the user and the hardware. By “user” not only
indicate end user or person rather it can refer to an application, a
piece of code that a programmer creates, like a word processor or an
email client.
Native Library(Middleware)
Android Runtime
Application Framework
Applications
1) Linux Kernel: is the lowest layer in the diagram responsible for interfacing with the
hardware, various services like memory management, power management and
executions of processes.
Linux is a very stable OS and is quite ubiquitous itself. we can find it in many places like
server hardware on data centers, appliances, medical devices, and so forth.
❖ It is the heart of android architecture that exists at the root of android architecture.
Cont’d
2) Native Libraries: on the top of Linux Kernel low-level libraries like SQLite,
OpenGL, WebKit, FreeType, and so on. These are not part of the Linux
kernel but are still low level and as such are written mostly in C/C++.
3) Android Runtime:
The Android Runtime (ART) is the system that runs your compiled code on
an Android device. It first appeared on Android with the release of KitKat
and became the standard way of running code in Lollipop.
Cont’d[ART]
It is the successor of DVM (Dalvik virtual machine)
Dalvik is a JIT (Just in time) compilation based engine i.e. instead of
compiling the whole app to machine code it compile small
chunk(part of) code during runtime.
The advantage is it will require low memory usage.
ART is equipped with Ahead-of-Time compiler(AOT) i.e. During the
app’s installation phase, it statically translates the DEX bytecode into
machine code and stores in the device’s storage
The advantage
Apps run faster as DEX bytecode translation done during
installation.
Reduces startup time of applications as native code is directly
executed.
Improves battery performance as power utilized to
interpreted byte codes line by line is saved.
4) Application Framework:
It sits on top of both the low-level libraries and the Android Runtime because it
needs both. This is the layer that we will interact with as an application developer
because it contains all the libraries we need to write apps. It includes Android API’s
such as UI (User Interface), telephony, resources, locations, Content Providers
(data) and package managers. It provides a lot of classes and interfaces for
android application development.
5) Applications:
On the top of android framework, there are applications. All applications such as
home, contact, settings, games, browsers are using android framework that uses
android runtime and libraries. Android runtime and native libraries are using linux
kernel
Android- Environment Setup
In order to write an Android application, we are going to need a
development environment.
Google has made a very useful tool for all Android Developers,
the Android Studio.
Android Studio is the official Integrated Development
Environment (IDE) for Android app development, based on
JetBrains’ IntelliJ. On top of IntelliJ's powerful code editor and
developer tools, Android Studio offers even more features that
enhance your productivity when building Android apps, such as:
• A flexible Gradle-based build system
• A fast and feature-rich emulator
• A unified environment where you can develop for all
Android devices etc.
Cont’d
➢ System Requirement
• Microsoft Windows 7, 8, or 10 (32- or 64-bit)
• macOS 10.10 (Yosemite or higher)
• Linux (Gnome or KDE Desktop), Ubuntu 14.04 or higher; 64-bit
capable of running 32-bit applications
• GNU C Library (glibc 2.19 or later) if you’re on Linux
➢ Hardware Requirement
For the hardware, your workstation needs to be at least
• 4GB RAM minimum (8GB or more recommended)
•2GB of available HDD space (4GB is recommended)
•1280 x 800 minimum screen resolution
Install Android Studio
AAU-SIS - 2019
Launch Android Studio and click “Configure” , then choose
“Preferences” from the drop-down list.
The “Preferences” option opens the Preferences dialog. On the left-
hand side, go to Appearance & Behavior ➤ System Settings ➤
Android SDK.
Download the API levels you want to target for your application
Make sure You install the following tools in SDK Tools :
❖ Android SDK Build Tools
❖ Android SDK Platform Tools
❖ Android SDK Tools
❖ Android Emulator
❖ Support Repository
❖ HAXM Installer (Hardware Acceleration)
Hardware Acceleration
An Android Virtual Device or AVD is an emulator where you can run
your apps.
Running on an emulator can sometimes be slow; this is the reason why
Google and Intel came up with HAXM
HAXM It is an emulator acceleration tool that makes testing your app a
bit more faster.
Cont’d
Note: If you are on the Linux platform, you cannot use HAXM even if
you have an Intel processor. KVM(Kernel-based Virtual Machine) will
be used in Linux instead of HAXM.
Test Our APP
We can use
❖ Android Emulator
❖ Physical device(our phone)
➢ Activity: specifies what the app does and how it should interact with
the user.
E.g. An Activity can be made so a user can view a single
email or maybe fill up a form.
❑ 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.
➢ Services: They handle background processing associated with an
application.
The Program can be run without freezing the user interface.
E.g we can use Services when our app is supposed to download a file from the
web or maybe play music.
➢ Broadcast receivers: respond to broadcast messages from other applications
or from the system.
you want your app to react in some way when a system event occurs.
A simple scenario can be having built a music app, and you want
it to stop playing music if the headphones are removed. How can your
app tell when these events occur?.
Events example: device running low on power, a new incoming phone call, or
the system getting booted. You can listen for these events by creating
a broadcast receiver.
➢ Content Providers: A content provider component supplies data from
one application to others on request.
• Interface that allows apps to share data in a controlled way
• It allows you to perform queries to read the data, insert new records,
and update or delete existing records.
Using Intent, you can forward data in an app. For example Messaging
app to send the text you pass to it.
But what if you want to use another app’s data in your own app?
For example, what if you want to use Contacts data in your app to
perform some task, or insert a new Calendar event?
You can’t access another app’s data by interrogating its database,
Instead, you use a content provider.
Additional Components
Intent: refers the message that is passed between components such as activities,
content providers, broadcast receivers, services etc.
Intent meaning is intention or purpose. it can be described as the intention to do
action.
Android intents are mainly used to:
❖ Start the service
❖ Launch an activity
❖ Display a web page
❖ Broadcast a message etc.
The following image shows the root <manifest> element with the package name
“com.example.myapp”
The next images shows how we declare Activity
Cont’d
AAU-SIS - 2019
Every Android project needs a gradle for generating an apk from
the .java and .xml files in the project
E.g. Converts the java files into dex files and compresses all of them
into a single file known as apk that is actually used.
This is an auto generated file which contains compileSdkVersion,
buildToolsVersion, applicationId, minSdkVersion, targetSdkVersion,
versionCode and versionName
There are two types of build.gradle scripts
Top-level build.gradle
Module-level build.gradle