Lecture07 - Components of Android Application

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

Mobile Programming

Components of an android application


Components of android application
 An android application is made up of several components ,
 These components are also known as building blocks or
application frame work elements.
 They include the following :
 Content Providers

 Windows

 Activities

 AndroidManifest.xml

 Intents, Intent Filter and intent receivers

 Services

 Layouts

 Broadcast receivers
1. Activity
 An activity is a class that presents a visual user interface (screen)

for one task the user can do.


 A user can move through screens by starting other activities.

• Examples:

An activity for displaying buttons for


An activity presenting login screen Allowing user to select an option
Activities
Implementing an activity
Activity stack

 Activities are stacked (arranged) like a deck of cards


 New activities are placed on top and only one activity is
visible at a time.
2. Intent

 An intent is a message that describes a desired action, data


to be acted upon, and the category of component that
should perform the action
 Intent is mostly used to launch specific activities e.g. send
an email, view user contacts
3. Service

A Service is a class without a visual interface so that it an be executed in


the background.
Service do not interact with the user
It is usually used for performing long tasks.
A service can be implemented as follows:

Example
Music player: Keeps playing even though user is navigating to other parts
of the application
Searching Service: that fetch data over the network without blocking user
interaction with an activity.
4. Content Provider
Content providers are objects that can retrieve and store data in
data storage mechanism such as SQLite or datafile
SQLite is an optimized dbms that runs on android .
Content Provider enables applications to share data.
It is the only way to share data across packages.
 For Example, any application can access the contacts database

8
4. Content Provider

 Sample code for creating content provider:


5. Android Manifest File


An android application must have android manifest file, which is
Generated automatically. Its functions include:
1. Describes application components such as activities, intents,
services, Notifications and content etc.
2. Declares the name of java package for the application.
3. Declares the minimum version of android sdk (minsdk) that is
required to run the application.
4. Declares the permissions that application must have in order to
access some APIs or other application.
5. It declares the permission that others are required in order to
access it's own components.
5. Android Manifest File: Example
6. Broadcast Receivers
 Broadcast Receiver is a class that receive and react to
broadcast intents.
 It is implemented as a subclass of BroadcastReceiver class
and each message is broadcasted as an Intent object.

 Examples of Broadcast intents are:


 Low battery, power connected, shutdown, timezone
changed, etc.
6. Broadcast Receivers

 Sample Code for creating a broadcast:

 Applications can initiate broadcasts by passing to any of the following


methods:
 Context.sendBroadcast(Intent intent)

 Context.sendOrderedBroadcast(),

 Context.sendStickyBroadcast()
7. Resources

 Resources refers to external elements that are used or


shared by components of the application.
 They include strings, constants and Drawable pictures.
8Layouts

 Layouts refers to ViewGroups that control format and


appearance of the views.
 Examples are:
1. Linear layout

2. Relative layout,

3. Table layout,

4. Grid layout

5. and tab layout


End

Thank You

Questions

You might also like