Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

Android Components

Vivek Nadar

Application Components

There are 4 types of application components


(1) Activities visual user interface focused
on a single thing a user can do
(2) Services no visual interface
they run in the background

(3) Broadcast Receivers


receive and react to broadcast announcements
(4) Content Providers
allow data exchange between applications

What is an Activity ?
An Activity means a single screen with a user interface.
An application usually consists of multiple activities
that are loosely bound to each other.
Activity generally provides a user with an interactive screen to do
something like:
Dialing the phone, Viewing a map, etc.
Every screen in an application,is an activity by itself.

Intents

Intents are used as a message-passing mechanism, that works both within


application and between applications.
Two types of Intents:

1) Implicit
Implicit does not specify a component. Instead,it includes enough
information for the system to determine which of the available
components is best to run for that intent.

Example :
Intent webIntent = new
Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(webIntent);

Intents...(2)
2) Explicit Intents

Explicit Intents explicitly defines the component which should be


called by the Android system, by using the Java class as identifier.
e.g. Intent launchExplicitIntent = new Intent(this,Game.class);
startActivity(launchExplicitIntent);

Program Demo

2. Services
A Task that runs in the background without
the user's direct interaction.

A service does not have a visual user interface.

A service,by default runs in the main thread of the application

that hosts it.

Examples

Network Downloads

Playing Music

Checking updates for an application

Program Demo

3. Broadcast receiver

A Broadcast receiver is a component that responds to


system-wide Broadcast announcements.

Many broadcasts originate from the system - for e.g.


a Broadcast announcing that the
screen has turned off, the battery is low,
a picture was captured or an SMS is received.

Broadcast receiver...(2)

An Application can also initiate broadcast


for e.g.to let other Applications know that
some data has been downloaded to the device
and is available for those application to use.

It creates a status bar notification to alert the user when a


broadcast event occurs.

4. Content Providers

Shared set of data.

Makes some of the application data

available to other applications

It is the only way to transfer data between applications in


Android (no shared files,

no shared memory,no pipes, etc.)

You might also like