Hello Everyone!
This article is based on the different components of Android. There are some essential components which are the building blocks of any android new project. Each component has its unique feature and maximum components must be included in any android project to improve the functionality.
The
android building blocks question has also been asked in university exams (sometimes along with the Android Architecture).
There
are some essential components which makes up the building blocks of any android
project. Every component is an entry point through which the system or a
user can enter the app. Some components rely upon others. These loosely coupled
components are bound by the application manifest file which contains description
of each component and how they interact. The manifest file also contains the
app’s metadata, its hardware configuration and platform requirements, external
libraries and required permissions.
The following are the main components of an android app-
1)
Activities-
An
activity is a window that contains the user interface of your applications. An
application can have zero or more activities. Typically, applications have one
or more activities, and the main aim of an activity is to interact with the user.
From the moment an activity appears on the screen to the moment it is hidden,
it goes through a number of stages, known as an activity’s life cycle.
Most
applications contain multiple screens, which means they comprise multiple activities.
Typically, one activity in an app is specified as the main activity, which
is the first screen to appear when the user launches the app. Each activity can
then start another activity in order to perform different actions. For example,
the main activity in a simple e-mail app may provide the screen that shows an
e-mail inbox. From there, the main activity might launch other activities that
provide screens for tasks like composing e-mails and opening individual e-mails.
2)
Services-
These
are like invisible workers of our application. These components run at back-end,
updating the data sources and Activities, triggering Notification and also
broadcast Intents. They also perform some tasks when applications are not
active. A service can be used as a subclass of class Service.
3)
Content Providers-
It
is used to manage and persist the application data, also typically interact with
SQL database. They are also responsible for sharing the data beyond the
application boundaries. The Content Providers of a particular application can
be configured to allow access from other applications, and the Content
Providers exposed by other applications can also be configured.
A content provider should be a sub class of the class ContentProvider.
4)
Intents-
It
is a powerful inter-application message-passing framework. They are extensively
used throughout Android. Intents can be used to start and stop Activities and
Services, to broadcast messages system-wide or to an explicit Activity, Service
or Broadcast Receiver or to request an action be performed on a particular
piece of data. There are two types of intents-
(a) Explicit Intent − It going to connect the internal world
of an application such as start activity or send data between two
activities. Explicit Intents have specified a component which
provides the exact class to be run.
(b) Implicit Intents- They have not specified a component;
instead, they must include enough information for the system to determine which
of the available components is best to run for that intent.
(To know more about Intents, click here!)
5)
Broadcast Receivers-
They
are known to be intent listeners as they enable the application to listen the
Intents that satisfy the matching criteria specified by users. Broadcast Receivers
make the application to react to any received Intent thereby making them
perfect for creating event driven applications.
6)
Widgets-
These
are the small visual application components that one can find on the home
screen of the devices. They are special variation of Broadcast Receivers that
allow developers to create dynamic, interactive application components for users to
embed on their Home Screen.
7)
Notifications-
Notifications
are the application alerts that are used to draw user’s attention to some
particular app event without stealing focus or interrupting the current
Activity of the user. They are generally used to grab user’s attention when the
application is not visible or active, particularly from within a Service or
Broadcast Receiver. Examples: E-mail popups, Messenger popups etc.
8)
Fragments-
A Fragment represents
a behavior or a portion of user interface in a Fragment Activity. It can be
kind of considered as a sub-activity. A fragment has its own layout and its own
behavior with its own life cycle call-backs. You can add or remove fragments
in an activity while the activity is running. You can combine multiple
fragments in a single activity to build a multi-pane User Interface. A fragment can be used
in multiple activities. Fragment life cycle is closely related to the life
cycle of its host activity which means when the activity is paused, all the fragments
available in the activity will also be paused. A fragment can implement a
behavior that has no user interface component.
Types
of Fragments- Basically fragments are divided as three stages.
(a) Single frame fragments − Single
frame fragments are using for hand hold devices like mobiles, here we can show
only one fragment as a view.
(b) List fragments − Fragments
having special list view is called as list fragment.
(c) Fragments transaction − Using
with fragment transaction. we can move one fragment to another fragment.
9)
Views-
This
class represents the basic building block for user interface components. A View
occupies a rectangular area on the screen and is responsible for drawing and
event handling. View is the base class for widgets, which are used to
create interactive User Interface components (buttons, text fields, etc.).
The ViewGroup subclass is the base class for layouts, which are
invisible containers that hold other Views and define their layout properties.
All of the views in a window are arranged in a single tree. There are many
specialized subclasses of views that act as controls or are capable of
displaying text, images, or other content. Some of the common operations to
perform on view are- set properties, set focus, set up listener and set
visibility.
10)
Layouts-
A
layout defines the structure for a user interface in the application, such as in
an activity. All elements in the layout are built using a hierarchy of
view and ViewGroup objects. A View usually draws
something the user can see and interact with. Whereas a ViewGroup is
an invisible container that defines the layout structure for View and
other ViewGroup objects. Layout are extensions of the ViewGroup class
and are used to position child Views within your UI. Layouts can be nested,
letting you create arbitrarily complex UIs using a combination of layouts. The
six main layouts in android are- Linear Layout, Relative layout, Table layout,
Grid layout, Tab layout and List layout,
11)
Resources-
Resources
are the additional files and static content that your code uses, such as bitmaps,
layout definitions, user interface strings, animation instructions, and more.
One should always externalize app resources such as images and strings from the
code, so that you can maintain them independently. You should also provide
alternative resources for specific device configurations, by grouping them in
specially-named resource directories. At runtime, Android uses the appropriate
resource based on the current configuration. Some of the most common resources
are- animator, color, drawable, layout, values, menu, xml, font, etc.
12)
Manifest-
Every
app project must have an AndroidManifest.xml file at the root of
the project source set. The manifest file describes essential
information about your app to the Android build tools, the Android operating
system, and Google Play. This manifest file includes the app's package name,
which usually matches your code's namespace, the components of the app, which
include all activities, services, broadcast receivers, and content providers,
the permissions that the app needs in order to access protected parts of the
system or other apps and the hardware and software features the app requires,
which affects which devices can install the app from Google Play. In Android
Studio, a manifest file is already created and most of the essential manifest
elements are added which are essential for the app.
To know more about the Android Architecture, checkout the Android Architecture Stack.
Also check out Intents and the Different Types of Intents in Android.
Comments
Post a Comment