Unit II
Unit II
UNIT II
Introduction to Android: What is Android? Setting up
development environment, Dalvik Virtual Machine
& .apk file extension, Fundamentals: Basic Building
blocks - Activities, Services, and Broadcast Receivers &
Content providers. UI Components - Views &
notifications. Components for communication -Intents &
Intent Filters, Android API levels (versions & version
names).
Android … What?
SMARTPHONES
3
TABLETS EREADERS ANDROID TV GOOGLE GLASSES
?
What is Android
Android is a software package and linux based operating
system for smart devices such as tablet computers and
smart phones.
It is developed by Google and later the OHA (Open
Handset Alliance).
Java language is mainly used to write the android code
even though other languages can be used.
The goal of android project is to create a successful real-
world product that improves the mobile experience for
end users.
4 L Sukanya
The main advantage of adopting Android is
5 L Sukanya
Android is a combination of three components:
A free, open-source operating system for mobile devices.
An open-source development platform for creating mobile
applications.
Devices, particularly mobile phones, that run the Android
operating system and the applications created for it.
6 L Sukanya
Setting up development environment
Android supports java, kotlin, c++, c# etc. language to
develop android applications. Java is the officially
supported language for android.
There are four tools that you will need and they are
available on the Internet for free:
Java JDK latest version
Android SDK
Eclipse IDE for Java Developers (optional)
Android Development Tools (ADT) Eclipse Plugin
(optional)
7 L Sukanya
Tools used :
JDK 1.6
Eclipse IDE 3.7 , Indigo
Android SDK
Summary steps to develop an Android application :
Install Java(JDK)
Install Android SDK
Create an Android Virtual Device (AVD)
Create Android Project with Eclipse (Wizard)
Code it…
Start it in Android Virtual Device (AVD)
8 L Sukanya
Dalvik Virtual Machine
The Dalvik Virtual Machine (DVM) is an android virtual
machine optimized for mobile devices.
The javac tool compiles the java source file into the class
file.
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.
The dx tool takes all the class files of your application and
generates a single .dex file. It is a platform-specific tool.
The Android Assets Packaging Tool (aapt) handles the
packaging process.
9 L Sukanya
(Android programs are compiled into .dex (Dalvik
Executable) files, which are in turn zipped into a
single .apk file on the device.)
10 L Sukanya
APK File
An Android Package Kit (APK for short) is
11 L Sukanya
12 L Sukanya
Android Core Building Blocks
Four basic components of Android:
Activities
Services
Content Provider
Broadcast Receiver
13 L Sukanya
Android Core Building Blocks
An android component is simply a piece of code that
has a well defined life cycle e.g. Activity, Receiver, Service
etc.
Activity
What is an Activity in Android?
Activity is the entry point in an Android application that
a user can interact with.
To be more clear, an Activity is each and every single
screen that you look at your Android device to interact
with.
Activities are used to make interactions with the system
(device) and the apps.
14 L Sukanya
15 L Sukanya
“Services” is a component that runs in the background so that it can
perform long, running operations or perform work for remote processes.
EX: Suppose you have an automatic call recorder app on your device and
when a call comes, then it automatically starts recording the call.
Content-Provider:
The Content Providers are components that expose a specific set of data
to applications. They provide the tools to manage access and define
security for the data.
It is only needed to communicate and share that data outside the
application.
Broadcast Receiver The Broadcast Receiver is a component that can
receive and respond to any broadcast announcements.
For example, Broadcast in android is the system-wide events that can occur
when the device starts, when a message is received on the device or when
incoming calls are received, or when a device goes to an airplane mode, etc.
16 L Sukanya
Additional Components
images etc.
Layouts : View hierarchies that control screen format and
your application. The user can expand the notification bar and by
selecting the notification the user can trigger another activity.
Types of Notifications: 1. Toast Notifications 2. Status Bar
18 L Sukanya
Intent types
There are two types of intents:
Explicit intents
Explicit Intent specifies the component. In such case, intent provides
the external class to be invoked.
Intent i = new Intent(getApplicationContext(), ActivityTwo.class); st
artActivity(i);
Implicit intents
Implicit Intent doesn't specifiy the component. In such case, intent
provides information of available components provided by the system
that is to be invoked.
For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.javatpoint.com"));
startActivity(intent);
19 L Sukanya
Android API levels (versions & version names)
20 L Sukanya
21 L Sukanya