Android Building Blocks

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11
At a glance
Powered by AI
The key takeaways are that there are 4 main types of application components in Android - Activities, Services, Broadcast Receivers and Content Providers. Activities provide the visual user interface, Services run tasks in the background, Broadcast Receivers respond to system-wide announcements, and Content Providers share data between applications.

The four main types of application components are Activities, Services, Broadcast Receivers, and Content Providers. Activities provide visual screens for user interaction. Services run tasks without a user interface in the background. Broadcast Receivers respond to system-wide announcements. Content Providers allow sharing of data between applications.

An Intent is a messaging object used to request an action from other application components. There are two main types - implicit intents which don't specify a component and explicit intents which explicitly define the component to call. Intents are used for communication both within and between applications.

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

1) Implicit

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 Examples Network Downloads Playing Music Checking updates for an application

that hosts it.

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 It is the only way to transfer data between applications in Android (no shared files,

available to other applications

no shared memory,no pipes, etc.)

You might also like