0% found this document useful (0 votes)
6 views4 pages

Android Application Components

The document provides an overview of the main components used to build Android applications, which include Activities, Services, Content Providers, Broadcast Receivers, and Intents. Each component serves a specific purpose, such as Activities for user interfaces, Services for background processing, and Content Providers for data sharing between applications. The document briefly describes each component and their functionalities without going into detailed explanations.

Uploaded by

hemali kotak
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Android Application Components

The document provides an overview of the main components used to build Android applications, which include Activities, Services, Content Providers, Broadcast Receivers, and Intents. Each component serves a specific purpose, such as Activities for user interfaces, Services for background processing, and Content Providers for data sharing between applications. The document briefly describes each component and their functionalities without going into detailed explanations.

Uploaded by

hemali kotak
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Android Application Components

February 4, 2015 Android 9 Comments

In this article we will try to make an overview of the Android Application Components. That
is the various elements by which an Android Application is built.

There are mainly five types of components that are used to build an application. Actually these
are some objects defined in the Android SDK and provide different methods by which an
application can behave. As a developer we need only to call and extend these already defined
classes to use in our application.

These are the main Android Application Components:

 Activities
 Services
 Content Providers
 Broadcast Receivers
 Intents

I’m not going to give a full explanation on each of these components. You will learn how to use
these Android application components to build applications later, when we start actual
development. Now I’m giving you brief descriptions of each terms to make you familiar with the
basic concepts.

1. Activities
Activity is an individual user interface screen in an Android

Application where visual elements called Views (also


known as widgets) can be placed and the user can perform various actions by interacting with it.
Consider the figure. The whole window gives the user an interface to interact with and therefore
this complete screen makes an Activity. The controls placed in the window allows the user to
perform certain actions and are called Views or Widgets. In this example, there are five widgets,
they are TextView, EditText, AnalogClock and two Buttons. The widgets in an Activity can be
created in two different ways, by pure java code and by adding XML code to define the UI. The
latter is always preferred. An application can have more than one Activity and each Activity
operates independently, but can be linked to one another and each Activity you create must be
defined in your application’s manifest file. Each Activity in android will be subclass of Activity
class defined in Android SDK.

2. Services
A service is an Android application component that run in background and has no visual UI.
Services are used to perform the processing parts of your application in the background. While
the user is working on the foreground UI, services can be used to handle the processes that need
to be done in the background. A service can be started by another Android application
components such as an activity or other services and it will continue to run in the background
even after the user switches to another application. Thus services are less likely to be destroyed
by Android system to free resources, than Activities.
One typical example for the use of services is a music player application. We can use an activity
to select a music track from the SD card and to play it. When it starts playing, the user is able to
open another applications and the music plays in the background. This can be made possible only
by the use of Android Services. The Activity that chooses the music track actually invokes a
service that works in the background. Then it will continue playing in the background even after
the front end activity gets destroyed. At any time the user is able to come back to the activity and
use the seek bar to seek the track, select another track, or end playback. This means that the
service and the Activity that invoked the service are not completely independent, instead the
Activity is able to fully control the Service. Another example for a service is the downloading of
file from the internet. It should run in the background and continue downloading even after we
switches to another applications.

All Android services are implemented as a subclass of Service class defined in Android SDK.
There are two types of services in Android.

They are:

Unbound Services

Its a type of service which is not bounded to any components. Once started, it will run in the
background even after the component that started the service gets killed. It can be run in the
background indefinitely and should stop by itself after the operation its intended to carry out is
completed.

Bound Services

Its bound to other components and runs only till the component to which it is bounded runs.

3. Content Providers
Content providers in Android provides a flexible way to make data available across applications.
Suppose you are creating any type of data in your application (For example consider you are
creating a to do list in your application, then the list of things is a data) and you are storing it at
any storage location, it may be in the data base, file system or in any online storage space. Then
through content providers other applications are able to query, access or even modify the data
you’ve created, as long as your content provider allows it. In a similar way you can access the
data that other utilities have created, by using content providers. Example for content provider in
Android is the contacts database. The Content provider of contacts database allows other
applications to query, read, modify, and write the contacts info. Android comes with several
other built in Content providers that we can use in our application. All content providers are
implemented as a subclass of ContentProvider class which is defined in Android SDK.

4. Broadcast Receivers
Broadcast receivers are one of Android application components that is used to receive messages
that are broadcasted by the Android system or other Android applications. There are many
broadcasts that are initiated by the Android system itself and other applications can receive by
using Broadcast receiver. Examples of broadcasts initiated by the system are:

1. Warning that the battery is getting low

2. Screen turned off

3. Change of time zone

4. The camera has been used to take a picture

While programming, we can use Broadcast receivers to receive these broadcasted messages and
behave accordingly. Applications can also initiate broadcasts. We can initiate as many broadcasts
as we want and there’s no limits for that.

5. Intents
Actually intents are not one of Android application components, instead it is the component
activating mechanism in Android. It constitutes the core message system in Android and defines
a message to activate a particular component. For example, if you want to invoke a new activity
from your current activity, you need to fire an intent specifying the new activity. And if you want
to start other application from your activity, then also you need to fire an intent. That is by firing
an intent, you are telling the Android system to make something happen.

There are two types of Intents in Android:

Explicit Intents:

In explicit Intent, we are highly specific. We specify which activity should get active on
receiving the intent. These are usually used for application’s internal communications.

Implicit Intents:

In implicit Intent we are sending a message to the Android system to find a suitable Activity that
can respond to the intent. For example, to send an e-mail, we can use an intent. We will also
specify the data to be operated on, with the intent. On receiving the Intent, Android system will
invoke an Activity which is able to send e-mail messages with the data that we specified. If there
is more than one activity is capable of receiving the Intent, the system presents a chooser to the
user so that he can select which Activity/Application should handle it.

You might also like