Before getting started with android
programming, we need to know some of the basic components of Android
applications. These are the buildings blocks of Android applications. These
will let us understand Android application from scratch.
There are Following Components in android:
- Activities
-View/User Interface(UI)
-Intents
-Services
-Content Provider
-BroadCast Receiver
Activities:
An activity in Android represents a single screen with user interface. An android application typically consists of several activities. An activity interacts with the user to do one thing, only ONE, such as Unlock screen, dial a phone, view home etc. An application consists of multiple activities that are loosely bound together. But only one activity can be specified as main activity which is displayed while launching the application. Every time an activity starts previous activity is stopped but the data is preserved.
An activity in Android represents a single screen with user interface. An android application typically consists of several activities. An activity interacts with the user to do one thing, only ONE, such as Unlock screen, dial a phone, view home etc. An application consists of multiple activities that are loosely bound together. But only one activity can be specified as main activity which is displayed while launching the application. Every time an activity starts previous activity is stopped but the data is preserved.
For instance an email
application will have one activity to display list of new emails, another
activity to compose email, another activity for reading emails and so on.
The above figure show is the screen with multiple fields like TextView, EditText, Analog Clock and buttons so this is the best example of Activity.
View:
An activity
contains views and viewgroups. Views in Andriod are UI components that could be
used to build user interface. Examples are buttons, label, and text boxes. One
or more views can be grouped together into a ViewGroup. Types of View in
android.
- Basic Views
- List Views
- Picker Views
- Menus
- Display Views
- Additional Views
ViewGroup provides a layout where you can
order the appearance of views. Android support the following view groups.·
- LinearLayout
- TableLayout
- AbsoluteLayout
- FrameLayout
- RelativeLayout
- ScrollView
Services:
Services are something that does not require
user interface. It performs operation without user interaction in the
background but does not get initiated without user invocation. Another
component such as an activity should invoke. To be more technical, service does
not have an independent thread, they make use of the main thread from hosting
process. For instance you can download something while you get involved in some
other application, where download is a service running in background.
Services can be defined in the Manifest.xml as the below mentioned code.
<
service
android:name
=
".ServiceClassName"
/>
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.
Content Providers:
Android is embedded with SQLite Database where all your data gets stored.
Content providers in Android manage data that is being shared by more than one
application. Consider a case where your Contacts are stored in centralized
repository, so here many applications may require access to it or may even
require modifying it. In such cases these applications need to query the
centralized repository through content providers, so an application with proper
permissions can read or modify the Contacts based on permissions. Content
provider is concept evolved to manage common data based on permissions. This is
a critical concept that has led to develop in-house android applications in a
better way.
We will see in details about Content Providers with the Example in coming tutorials.
Broadcast Receivers:
Broadcast receiver is also a component where
you can register for system or application events. Once registered you will be
notified about the events. Broadcast originates from the system as well as
applications. Instance for broadcast originating from the system is ‘low
battery notification’. Application level is, like when you download an mp3
file, Mp3 player gets notified about it, and gets added to player list. For
this action to take place, mp3 player has to register for this event.
Many
system wide events broadcast their information. For example
·
When SMS / Call is received
·
Battery low
·
Network state Changed
·
Photo captured from camera
·
Phone Starts
We will see in details about BroadCast Receivers with the Example in coming tutorials.
Broadcast Receivers can be defined in the Manifest.xml as the below mentioned code.
<
receiver
android:name
=
".YourReceiver"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.BATTERY_LOW"
/>
</
intent-filter
>
</
receiver
>
Intent:
Intents are messages that allow components to
request activities from other components. Consider an activity requires another
activity to perform some functionality in such cases communication between
activities occurs via Intent.
We will see in details about Intent Class with the Example in coming tutorials.
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.
Android Components with Twitter Example:
No comments:
Post a Comment