2. UNIT I
ANDROID OVERVIEW
Introduction – Android SDK features – OHA
– Development framework – Getting started –
developing for android, mobile devices - ADT –
Creating an applications and activities -
Application manifest – Android Application Life
Cycle – Understanding application priority -
Externalizing resources – Android application
class – Android Activities
3. Development framework
In general, a framework is a real or conceptual structure
intended to serve as a support or guide for the building of
something that expands the structure into something useful.
An Android application framework is a software toolkit that
enables app developers to piece together a finished product
that meets the requirements of its proprietor.
4. Development framework
A framework provides the bones of an application, to be
fleshed out with graphics, animation, special features and
functionality.
The Application Framework layer provides many higher-
level services to applications in the form of Java classes.
5. Android architecture or Android software stack is
categorized into five parts:
Linux kernel
Native libraries (middleware)
Android Runtime
Application Framework
Application Layer
6.
7. 1) Linux kernel
• It is the heart of android architecture that exists
at the root of android architecture.
• Linux kernel is responsible for device drivers,
power management, memory management,
device management and resource access.
8. 2) Native Libraries
• Running on the top of linux kernel, Native libraries such as
WebKit, OpenGL, FreeType, SQLite, Media, C runtime
library (libc) etc.
• The WebKit library is responsible for browser support and
Internet security;
• SQLite is for database,
• FreeType for font support,
• Media for playing and recording audio and video formats.
9. Some key core Android libraries available to the Android
developer is as follows −
• android.app − Provides access to the application model and is
the cornerstone of all Android applications.
• android.content − Facilitates content access, publishing and
messaging between applications and application components.
• android.database − Used to access data published by content
providers and includes SQLite database management classes.
• android.opengl − A Java interface to the OpenGL ES 3D
graphics rendering API.
10. • android.os − Provides applications with access to standard
operating system services including messages, system services and
inter-process communication.
• android.text − Used to render and manipulate text on a device
display.
• android.view − The fundamental building blocks of application
user interfaces.
• android.widget − A rich collection of pre-built user interface
components such as buttons, labels, list views, layout managers,
radio buttons etc.
• android.webkit − A set of classes intended to allow web-browsing
capabilities to be built into applications.
11. 3) Android Runtime
In android runtime, there are core libraries and DVM
(Dalvik Virtual Machine) which is responsible to run
android application.
One of the key elements of Android is the Dalvik VM,
Android uses its own custom VM designed to ensure that
multiple instances run efficiently on a single device.
DVM is like JVM but it is optimized for mobile devices.
The Dalvik VM makes use of Linux core features like
memory management and multi-threading, which is
intrinsic in the Java language.
It consumes less memory and provides fast performance.
12. 4) Android Framework
On the top of Native libraries and android runtime, there
is android framework.
Android framework 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.
13. 5) Application Layer
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
kernal.
14. Android Core Building Blocks
An android component is simply a piece of code that has
a well defined life cycle e.g. Activity, Receiver, and
Service etc.
The core building blocks or fundamental components of
android are activities, views, intents, services, content
providers, fragments and AndroidManifest.xml.
15. Activity
An activity is a class that represents a single screen.
It is like a Frame in AWT.
View
A view is the UI element such as button, label, text field etc.
Anything that you see is a view.
Intent
Intent is used to invoke components. It is mainly used to:
• Start the service
• Launch an activity
• Display a web page
• Display a list of contacts
• Broadcast a message
• Dial a phone call etc.
16. • For example, 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);
17. Service
• Service is a background process that can run for a long time.
• There are two types of services local and remote.
• Local service is accessed from within the application
whereas remote service is accessed remotely from other
applications running on the same device.
Content Provider
• Content Providers are used to share data between the
applications.
• Fragment
• Fragments are like parts of activity.
• An activity can display one or more fragments on the screen
at the same time.
18. AndroidManifest.xml
• It contains information about activities, content providers,
permissions etc.
• It is like the web.xml file in Java EE.
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.
19. Android Activity Lifecycle
• Activity is one of the building blocks of Android OS.
• Activity is a screen that user interact with.
• Every Activity in android has lifecycle like created,
started, resumed, paused, stopped or destroyed.
• Activity is a class pre-written in Java Programming. An
activity is the single screen in android. It is like
window or frame of Java.
20. Android Activity Lifecycle methods
The 7 lifecycle methods of Activity describes how activity will
behave at different states.
•onCreate()
•onStart()
•onResume()
•onPause()
•onStop()
•onRestart()
•onDestroy
21. Android Activity Lifecycle methods
•onCreate() – Called when the activity is first created
•onStart() – Called just after it’s creation or by restart
method after onStop(). Here Activity start becoming visible
to user
•onResume() – Called when Activity is visible to user and
user can interact with it
•onPause() – Called when Activity content is not visible
because user resume previous activity
22. Android Activity Lifecycle methods
•onStop() – Called when activity is not visible to user
because some other activity takes place of it
•onRestart() – Called when user comes on screen or resume
the activity which was stopped
•onDestroy – Called when Activity is not in background
23.
24.
25.
26.
27.
28.
29. EXAMPLE
Following is the content of the modified main activity
file src/com.example.helloworld/MainActivity.java.
This file includes each of the fundamental life cycle
methods.
The Log.d() method has been used to generate log
messages −
30. package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
public class MainActivity extends Activity {
String msg = "Android : ";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event"); }
/** Called when the activity is about to become visible. */ @Override
protected void onStart() {
super.onStart();
Log.d(msg, "The onStart() event"); }
31. /** Called when the activity has become visible. */
@Override
protected void onResume() {
super.onResume();
Log.d(msg, "The onResume() event"); }
/** Called when another activity is taking focus. */
@Override
protected void onPause() {
super.onPause();
Log.d(msg, "The onPause() event"); }
32. /** Called when the activity is no longer visible. */
@Override
protected void onStop() {
super.onStop();
Log.d(msg, "The onStop() event"); }
/** Called just before the activity is destroyed. */
@Override
public void onDestroy() {
super.onDestroy();
Log.d(msg, "The onDestroy() event");
} }
33. ANDROID DEVELOPMENT TOOLS
• Android Development Tools (ADT) is a plug-in for the
Eclipse IDE that is designed to give you a powerful,
integrated environment in which to build Android
applications.
• ADT is the Android Developer Tools plug-in for Eclipse.
• ADT is about the useful code stuff: for example the libraries,
packages.
• The ADT plug-in for Eclipse uses the SDK tools as part of
its work.
34. ADT vs Android SDK
• The Android SDK contains the tools and
related files necessary to build an Android
application.
• SDK is actually about the tools: for example
Debugging.
35. Android Development Tools (ADT)
ADT plug-in incorporates many of the tools into the
Eclipse IDE, where you can access them from the DDMS
perspective, including the following:
Android Virtual Device and SDK Managers
Android Emulator
Dalvik Debug Monitoring Service (DDMS)
Android Debug Bridge (ADB)
Android Asset Packaging Tool (AAPT)
SQLite3
MkSDCard
36. Android Virtual Device and SDK Managers
• Used to create and manage AVDs and to download
SDK packages, respectively.
• The AVD hosts an Emulator running on a particular
build of Android,
• It specify the supported SDK version, screen
resolution, amount of SD card storage available, and
available hardware capabilities (such as touchscreens
and GPS).
37. Android Emulator
• Use the Emulator to test and debug your Android
applications
Dalvik Debug Monitoring Service (DDMS)
• Use the DDMS to monitor and control the Emulators on
which you’re debugging your applications.
Android Debug Bridge (ADB)
• A client-server application that provides a link to virtual and
physical devices. It lets you copy files, install compiled
application packages (.apk), and run shell commands.
38. Android Asset Packaging Tool (AAPT)
• Constructs the distributable Android package fi les (.apk).
SQLite3
• A database tool that you can use to access the SQLite
database fi les created and used by Android.
MkSDCard
• Creates an SD card disk image that can be used by the
Emulator to simulate an external storage card.
39. Creating an Applications and Activities
• Used to create and manage AVDs and to download
SDK packages, respectively.
• The AVD hosts an Emulator running on a particular
build of Android,
• It specify the supported SDK version, screen
resolution, amount of SD card storage available, and
available hardware capabilities (such as touchscreens
and GPS).