0% found this document useful (0 votes)
111 views

Introduction To Android

Android is a mobile operating system based on Linux. It includes APIs for building apps that interact with the hardware and run across various Android devices. The Android architecture consists of a Linux kernel at the bottom, native libraries and middleware, the Android runtime, application framework, and applications at the top. To develop Android apps, developers need to set up an environment including Android Studio, an Android Virtual Device, and use these tools to create a "Hello World" Android app.

Uploaded by

isac abram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views

Introduction To Android

Android is a mobile operating system based on Linux. It includes APIs for building apps that interact with the hardware and run across various Android devices. The Android architecture consists of a Linux kernel at the bottom, native libraries and middleware, the Android runtime, application framework, and applications at the top. To develop Android apps, developers need to set up an environment including Android Studio, an Android Virtual Device, and use these tools to create a "Hello World" Android app.

Uploaded by

isac abram
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

1

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?

 Android is a mobile operating system developed by Google, based


on the Linux kernel and designed primarily for touch screen mobile
devices such as smart phones and tablets. Android offers a unified
approach to application development for mobile devices.

 It started as an operating system for phones, but it has, since, made


its way into all sorts of places like TVs, car systems, watches, e-
readers, netbooks, and game consoles, among other things

 It’s a powerful development framework that includes everything you


need to build great apps using a mix of Java and XML
 Api level: is an integer value that uniquely identifies the framework API revision
offered by a version of the Android platform.

 Each Android platform version supports exactly one API Level

 The Android platform provides a framework API that applications can use to
interact with the underlying Android system.

 The framework API consist:

❖ A core set of packages and classes

❖ A set of XML elements and attributes for declaring a manifest file

❖ A set of XML elements and attributes for declaring and accessing resources

❖ A set of Intents

❖ A set of permissions that applications can request, as well as permission


enforcements included in the system
Cont’d
 Applications can use a manifest element provided by the framework
API, <uses-sdk> to describe the minimum and maximum API Levels
under which they are able to run, as well as the preferred API Level that
they are designed to support

 <uses-sdk> offers three key attributes:


❖ android:minSdkVersion: Specifies the minimum API Level on which the application
is able to run. The default value is "1".

❖ android:targetSdkVersion: Specifies the API Level on which the application is


designed to run.

❖ android:maxSdkVersion: Specifies the maximum API Level on which the application


is able to run. Declaring this attribute is not recommended because after the system
update the app may crash
Why Android?

 Android is the most popular mobile operating system, with more


than 2.5 billion devices activated and it offers a unified approach to
application development for mobile devices.

 By “unified” meaning developers need only develop for Android,


and their applications will be able to run on different devices
powered by Android.

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

 Larger Developer and Community reach


History of Android
 Initially, Andy Rubin founded Android Incorporation in Palo Alto,
California, United States in October, 2003.

 In 17th Aug 2005 Google bought Android Inc.

 In 2007, Google announces the development of android OS.

➢ In 2008, HTC launched the first android mobile.

❖ 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

Android OS basic screen provides a beautiful and intuitive user interface.

 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

SQLite, a lightweight relational database, is used for data storage purposes.

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

 Firebase Cloud Messaging (FCM)

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.

For instance Take the email app,

As we type each character, the app needs to communicate to the


hardware for the message to make its way to your screen and hard drive
and eventually send it to the cloud via your network
Cont’d

 Generally Operating System does three things:

➢ Manages hardware on behalf of applications.

➢ Provides services to applications like networking, security, memory

management, and so forth.

➢ Manages execution of applications; this is the part that allows us to

run multiple applications (seemingly) almost at the same time.

➢ Next, we try to see High Level Android System Architecture, It


consists of five Parts.
Cont’d
 Linux Kernel

 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++.

Webkit Library: For Browser Support

SQLite: For Database Support

FreeType: For Font Support

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

 Go to the official android website


https://developer.android.com/studio/
If you’re on Windows, do the following:
➢ 1. Unzip the installer file.
➢ 2. Move the unzipped directory to a location of your choice, for
example, C:\Users\myname\AndroidStudio.
➢ 3. Drill down to the “AndroidStudio” folder; inside it, you’ll find
“studio64.exe”. This is the file you need to launch. It’s a good idea
to create a shortcut for this file—if you right-click studio64.exe and choose
“Pin to Start Menu,” you can make Android Studio available from the
Windows Start menu; alternatively, you can also pin it to the Taskbar.
Configuring 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)

 Android Emulator: allows us to run our app on an Android virtual


device (AVD), which behaves just like a physical Android device.
 AVD running in the Android emulator looks like the
following figure
 The AVD here is setup to Nexus 5x and Api level 25.
 If we want to know how the app behaves in our physical device.
1) Enable USB debugging on your device

 On your device, open “Developer options” [greater than 4.0 version]


 To enable “Developer options,”
go to Settings → About Phone and tap the build number seven times
 Turn on USB debugging
2) Set up your system to detect your device
 install a USB driver
3) Plug your device into your computer with a USB cable
 Your device may ask you if you want to accept an RSA key that allows USB
debugging with your computer. If it does, you can check the “Always allow
from this computer” option and choose OK to enable this.
Android Core Building Blocks

Fig. Logical representation of an Android app


Cont’d
 The Key building block of android are:
❖ Activity
❖ Services
❖ Broadcast receivers
❖ Content Providers

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

 Fragments: Represents a portion of user interface in an Activity.


❖ We use fragments to create reusable codes in an activity.
Android Project Structure
Useful File in the project
 In the previous diagram
The root folder “App” refers the name of your project. The “app” folder
is a module in your project. Inside this there is “build” folder it contains
files that Android Studio creates for you. You don’t usually edit anything
in this folder.
R. Java contained in this folder: build/generated/source
Every Android project needs a file called R.java, which is created for
Android uses this file to keep track of resources in the app.
“Src” directory contains source code you write and edit. It contains
two important directory
Java
Res
Cont’d
 Java: The java folder contains any Java code you write. Any activities
you create live here.
inside this directory we get MainActivity.java
MainActivity.java defines an activity. An activity tells Android how the
app should interact with the user.
 Res: inside this directory we have layout and values.
In Layout folder there is activity_main.xml. This file defines a layout. A
layout tells Android how your app should look.
In Values folder we found different files like strings.xml, colors.xml,
styles.xml
 Strings.xml: is a String resource file. It includes Strings such as the app’s
name and any default text values. Other files such as layouts and
activities can look up text values from here.
 colors.xml file contains color resources of the Android application. Different color
values are identified by a unique name that can be used in the Android
application program.
 Styles.xml file contains resources of the theme style in the Android application.
Additional folders in res include Mipmap and drawable
Mipmap: Mipmap folder contains the Image Asset file that can be used in Android
Studio application.
A mipmap is an image that can be used for application icons, and they’re held in
mipmap* folders in app/src/main/res. You can generate the following icon types
like Launcher icons, Action bar and tab icons, and Notification icons.
Drawable:
A Drawable folder contains resource type file (something that can be drawn).
Drawables may take a variety of file like Bitmap (PNG, JPEG), Nine Patch, Vector
(XML), Shape, Layers, States, Levels, and Scale.
 AndroidManifest.xml: Every Android app must include a file called
AndroidManifest.xml at its root.
 The manifest file defines the structure and metadata of our
application, its components, and its requirements. This file includes
nodes for each of the Activities, Services, Content Providers and
Broadcast Receiver that make the application and using Intent
Filters and Permissions, determines how they co-ordinate with each
other and other applications.
Package name in Manifest File

 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

 The following activity name is resolved to


“com.example.myapp.MainActivity”
Build.gradle 40

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

You might also like