You are on page 1of 7

Unit I

Android is a comprehensive open source platform based on Linux and championed by Google. It’s
a powerful development framework that includes everything you need to build great apps using a
mix of Java and XML. What’s more, it enables you to deploy those apps to a wide variety of
devices — phones, tablets and more.

A typical Android app is comprised of one or more screens. You define what each screen looks
like using a layout to define its appearance. Layouts are usually defined using XML, and can
include GUI components such as buttons, text fields, and labels.

Features of Android
As Android is open source and freely available to manufacturers for customization, there are no
fixed hardware and software configurations. However, Android itself supports the following
features:
Storage — Uses SQLite, a lightweight relational database, for data storage. Chapter 6 discusses
data storage in more detail.
Connectivity — Supports GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth (includes
A2DP and AVRCP), WiFi, LTE, and WiMAX. Chapter 8 discusses networking in more detail.
Messaging — Supports both SMS and MMS. Chapter 8 discusses messaging in more detail.
Web browser — Based on the open-source WebKit, together with Chrome’s V8 JavaScript engine
Media support — Includes support for the following media: H.263, H.264 (in 3GP or MP4
container), MPEG-4 SP, AMR, AMR-WB (in 3GP container), AAC, HE-AAC (in MP4 or
3GP container), MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP
Hardware support — Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor,
and GPS
Multi-touch — Supports multi-touch screens
Multi-tasking — Supports multi-tasking applications
Flash support — Android 2.3 supports Flash 10.1.
Tethering — Supports sharing of Internet connections as a wired/wireless hotspot
The Android platform

The Android platform is made up of a number of different components. It includes core


applications such
as Contacts, a set of APIs to help you control what your app looks and how it behaves, and a whole
load
of supporting files and libraries. Here’s a quick look at how they all fit together:
The Android OS is roughly divided into five sections in four main layers:

Linux kernel — This is the kernel on which Android is based. This layer contains all the lowlevel
device drivers for the various hardware components of an Android device.
Libraries — These contain all the code that provides the main features of an Android OS. For
example, the SQLite library provides database support so that an application can use it for
data storage. The WebKit library provides functionalities for web browsing.
Android runtime — At the same layer as the libraries, the Android runtime provides a set of core
libraries that enable developers to write Android apps using the Java programming language. The
Android runtime also includes the Dalvik virtual machine, which enables every Android
application
to run in its own process, with its own instance of the Dalvik virtual machine (Android
applications are compiled into the Dalvik executables). Dalvik is a specialized virtual machine
designed specifically for Android and optimized for battery-powered mobile devices with limited
memory and CPU.
Application framework — Exposes the various capabilities of the Android OS to application
developers so that they can make use of them in their applications.
Applications — At this top layer, you will find applications that ship with the Android device
(such as Phone, Contacts, Browser, etc.), as well as applications that you download and install
from the Android Market. Any applications that you write are located at this layer.
Activities

An activity represents a single screen with a user interface just like window or frame of Java.

Life Cycles of the Activity

During its lifetime, each activity of an Android program can be in one of several states, as shown
in Figure . You, the developer, do not have control over what state your program is in. That’s all
managed by the system. However, you do get notified when the state is about to change through
the onXX() method calls.
You override these methods in your Activity class, and Android will call them at the appropriate
time:

• onCreate(Bundle): This is called when the activity first starts up. You can use it to perform one-
time initialization such as creating the user interface. onCreate( ) takes one parameter that is either
null or some state information previously saved by the onSaveInstanceState( ) method.

• onStart( ): This indicates the activity is about to be displayed to the user.

• onResume( ): This is called when your activity can start interacting with the user. This is a good
place to start animations and music.

• onPause( ): This runs when the activity is about to go into the background, usually because
another activity has been launched in front of it. This is where you should save your program’s
persistent state, such as a database record being edited.

• onStop( ): This is called when your activity is no longer visible to the user and it won’t be needed
for a while. If memory is tight,
onStop( ) may never be called (the system may simply terminate your process).

• onStart( ): This indicates the activity is about to be displayed to the user.

• onResume( ): This is called when your activity can start interacting


with the user. This is a good place to start animations and music.

• onPause( ): This runs when the activity is about to go into the background, usually because
another activity has been launched in front of it. This is where you should save your program’s
persistent state, such as a database record being edited.

• onStop( ): This is called when your activity is no longer visible to the user and it won’t be needed
for a while. If memory is tight, onStop( ) may never be called (the system may simply terminate
your process).
Android Intent is the message that is passed between components such as activities,
content providers, broadcast receivers, services etc.

It is generally used with startActivity() method to invoke activity, broadcast receivers etc.

The dictionary meaning of intent is intention or purpose. So, it can be described as the
intention to do action.

The LabeledIntent is the subclass of android.content.Intent class.

Android intents are mainly used to:

o Start the service

o Launch an activity

o Display a web page

o Display a list of contacts

o Broadcast a message

o Dial a phone call etc.

Types of Android Intents

There are two types of intents in android: implicit and explicit.

1) Implicit Intent

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.Intent.com"));
startActivity(intent);
2) Explicit Intent

Explicit Intent specifies the component. In such case, intent provides the external class to be
invoked.

Intent i = new Intent(this, ActivityTwo.class);

The first parameter tells Android which object the intent is from, and you can use the word this to
refer to the current activity. The second parameter is the class name of the activity that needs to
receive the intent.
startActivity(i);
This tells Android to start the activity specified by the intent. Once Android receives the intent, it
checks everything’s OK and tells the activity to start. If it can’t find the activity, it throws an
ActivityNotFoundException.

Passing Data between Activities

You can add extra information to this intent that can be picked up by the activity you’re targeting
so it can react in some way. To do this, you use the putExtra() method

intent.putExtra("message", value);

where message is a String name for the value you’re passing in, and value is the value. The
putExtra() method is overloaded so value has many possible types. As an example, it can be a
primitive such as a boolean or int, an array of primitives, or a String.

How to retrieve extra information from an intent

getIntent() returns the intent that started the activity, and you can use this to retrieve any extra
information that was sent along with it. How you do this depends on the type of information that
was sent.
As an example, if you know the intent includes a String value with a name of “message”, you
would use
the following:
Intent intent=getIntent();

String s1=intent.getStringExtra(“Message”);

You might also like