These are the main Android Application Components :
- Activities
- Services
- Content Providers
- Broadcast Receivers
- Intents
|
Android Activity |
|
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."
For ex :
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 and used to perform the processing parts of your application in the background.". A service will continue to run in the
background even after the user switches to another application.
For ex :
While user listen song on Music Player. He/she perform other activity at same time.
All Android services are implemented as a subclass of Service class
defined in Android SDK. There are two types of services in Android.
- Bound Service : Its bound to other components and runs only till the component to which it is bounded runs.
- Unbound Service : It's not bounded to any components. Once started, it will run in the
background even after the component that started the service gets
killed means it runs in the background indefinitely
3. Content Providers :
"It's a flexible way to make data
available across applications."
For ex :
- You are creating any type of data
in your application and you are
storing it 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.
- 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 :
"It's
used to receive messages that are broadcasted by the Android system or
other Android applications."
There are many broadcasts initiated
by the Android system itself for example
- Take a picture from Camera
- Turn off Screen
- Change time zone
- Warning battery is getting low
5. Intents :
"Actually It's not a components, it is the activating mechanism in Android."
For ex :
- 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 :
- 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 ex :
- To
send an e-mail, we can use an 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.
- Explicit Intents :
"We specify which activity should get active on receiving the intent.
These are usually used for application’s internal communications."