1. Application Building Blocks & Components
Android applications are composed of one or more application
components
- Activity
- Services
- Intents
- Content Providers
- Broadcast Receivers
Dept. of Computer Science and
Engineering
2. Activity
• An activity corresponds to a screen. If an application is
composed of several screens, it has an activity for each
screen.
• Each activity is a class that extends the base class called
Activity. It has a graphical user interface made of
views, and it responds to events. When you change
screen, a new activity is launched and It can return a
value
• The graphical interface of an activity is described by a
Layout Dept. of Computer Science and
Engineering
3. For example,
An email application might have one activity that shows a list of
new emails, another activity to compose an email, and another
activity for reading emails.
Dept. of Computer Science and
Engineering
4. Application
• Create an application which calls one Activity
into another
Dept. of Computer Science and
Engineering
5. Intent
• Intents are verbs for android devices, which defines actions
and are made effective by a new screen
E.g. CALL, SEND_MESSAGE.
• An intent is made up of an action and data that are URI.
• Components of an application — activities, services, and
broadcast receivers , are activated through messages, called
intents.
• In each case, the Android system finds the appropriate
activity, service, or set of broadcast receivers to respond to
Dept. of Computer Science and
the intent, instantiating them if necessary.
Engineering
6. • Examples of actions: MAIN, VIEW, EDIT, PICK.
If one wants to see a card about a person, an intent is defined. The
action is VIEW and the data is the URI which enables access to this
card.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>
Dept. of Computer Science and
Engineering
7. IntentFilters
• Describes how the action should apply.
• To inform the system which implicit intents they can handle
activities, services, and broadcast receivers
IntentReceiver
• It is an object that responds to external events. It can operate in the
application or it can start an application.
• Example of intent, view a webpage: VIEW for action and for data
http://www.linkToStuff.org.
Dept. of Computer Science and
Engineering
8. Content Provider
• Data stored by a program, in the form of files or SQLite databases
are private and may not be used by other applications.
• That is to say, a SQLite database created on Android by one
application is usable only by that application, not by other
applications. Databases created in Android are visible only to the
application that created them
• So, if you need to share data between applications, you need to
use the content provider.
Dept. of Computer Science and
Engineering
9. For example,
• The Android system provides a content provider that manages the
user's contact information. As such, any application with the proper
permissions can query part of the content provider to read and
write information about a particular person.
• Content providers are also useful for reading and writing data that is
private to your application and not shared. For example, the Note
Pad sample application uses a content provider to save notes.
Dept. of Computer Science and
Engineering
10. To query a content provider, you provide a query string in the form of
a URI, with an optional specifier for a particular row, using the
following syntax:
<standard_prefix>://<authority>/<data_path>/<id>
Similarly, to retrieve all the contacts stored by the Contacts
application, the URI would look like this:
content://contacts/people
Dept. of Computer Science and
Engineering
11. Broadcast receivers
• A broadcast receiver is a component that responds to system-
wide broadcast announcements.
• Many broadcasts originate from the system—for example, a
broadcast announcing that the screen has turned off, the battery
is low, or a picture was captured.
• Applications can also initiate broadcasts—for example, to let
other applications know that some data has been downloaded to
the device and is available for them to use.
• Although broadcast receivers don't display a user interface, they
may create a status bar notification to alert the user when a
broadcast event occurs.
Dept. of Computer Science and
Engineering
12. Services
• A service is a component that runs in the background to
perform long-running operations . It’s a faceless
component of a process.
• A service does not provide a user interface.
• A service is designed to operate independently of the
screen, can update your data source and activities, and
trigger specific notations.
• The best example is the music player that can work in
background and when of Computer Science and in some other activity.
Dept. we can be
Engineering
14. Types of Layout
• Absolute Layout
• Frame Layout
• Linear Layout
• Relative Layout
• Table Layout
Dept. of Computer Science and
Engineering
15. AbsoluteLayout
• For each view you
add, you specify the
exact screen
coordinate to display
on the screen
Dept. of Computer Science and
Engineering
16. Frame Layout
• designed to display a
single item at a time.
• element will be
positioned based on
the top left of the
screen
Dept. of Computer Science and
Engineering
17. Linear Layout
• organizes elements along a single line.
• Can specify whether that line is vertical or
horizontal using android:orientation.
Dept. of Computer Science and
android:orientation
Engineering changed to horizontal.
18. Relative Layout
• lays out elements
based on their
relationships with one
another, and with the
parent container.
Dept. of Computer Science and
Engineering