Android Application Components

Android Application Components (Activities, Intents, Views, Layouts, Services)

In android, application components are the basic building blocks of an application and these components will act as an entry point to allow system or user to access our app.
Following are the basic core application components that can be used in Android application.

  1. Activities 
  2. Intents
  3. Content Providers
  4. Broadcast Receivers 
  5. Services 
  6. Android Activities

In android, Activity represents a single screen with a user interface (UI) and it will acts an entry point for user’s to interact with app. 
For example, a contacts app which is having a multiple activities like showing a list of contacts, add new contact, and another activity to search for the contacts. All these activities in contact app are independent of each other but will work together to provide a better user experience.
To know more about Activities in android check this Android Activities.

Android Intents

In android, Intent is a messaging object which is used to request an action from another component.
In android, intents are mainly used to perform following things.
Starting an Activity
Starting a Service
Delivering a Broadcast
Display a list of contacts
Broadcast a message
Dial a phone call etc.

There are two types of intents available in android, those are
Implicit Intents

Explicit Intents

To know more about Intents in android check this Android Intents.

Android Services:-

In android, Service is a component which keep an app running in the background to perform long running operations based on our requirements. For Service, we don’t have any user interface and it will run the apps in background like play music in background when the user in different app.
We have two types of services available in android, those are
Local Services
Remote Services

Android Broadcast Receivers:-

In android, Broadcast Receiver is a component which will allow a system to deliver events to the app like sending a low battery message to the app. The apps can also initiate broadcasts to let other apps know that required data available in a device to use it.
Generally, we use Intents to deliver broadcast events to other apps and Broadcast Receivers use status bar notifications to let user know that broadcast event occurs.
Android Content Providers:-

In android, Content Providers are used to exchange the data between the apps based on the requests. The Content Providers can share the app data that store in the file system, SQLite database, on the web or any other storage location that our app can access.
By using Content Providers, other apps can query or modify the data of our app based on the permissions provided by content provider. For example, android provides a Content Provider (ContactsContract.Data) to manage contacts information, by using proper permissions any app can query the content provider to perform read and write operations on contacts information.

Additional Android Application Components

There are some additional components as well that are used with above fundamental components. They are –

A. Fragments
B. Views
C. Layouts
D. Intents
E. Manifest
F. Resources

A. Fragments

A fragment is a part of user interface in a activity. You can use one or more fragments in an activity. You can assume fragment as a modular part of activity that has it’s own life cycle, can receive it’s own input, can be added or removed dynamically, while activity is running. A Fragment must always be embedded in activity because it’s life cycle is affected by host activity life cycle. i.e. you can use fragment without activity.

B. Views

This is basic building block for user interface component. It is rectangular area on the screen. We can draw or handle some events in this rectangular area. Also, View is base class for widgets( used to create ui components).

C. Layouts
A layout is visual structure for any user interface. For example, UI for activity, widgets, fragments etc. You can declare layouts in 2 ways.

1. Statically: You can declare layouts in xml file. xml file is added in res => layout folder of any android application.

2. Dynamically: You can declare layouts at runtime as well. To create layouts at runtime, you would need to add related code in java file.

D. Intents

Intent is an abstract information related to an operation to be performed. Intent is used to communicate between different android components in several ways. Some of them are –

(i) Start an Activity: You can use intent to start an activity from another activity or fragment class.

(ii) Start a Service: Same as Activity, You can use intent to start an service from a activity or fragment class.

(iii) Broadcasting a message: You can use intent to broadcast a message so that proper action is taken against the message broadcasted.

E. Manifest

Every android application must have AndroidManifest.xml file in it’s root directory. It contains a short description of the android application. For example, It contains the package name of the application(that acts as unique identifier of the application), informations about the components of the application(Activities, services, broadcast receivers, content providers), permissions needed to run the application, minimum level of api that application need to run etc.

F. Resources

There are many more things you need while creating UI for an activity in android application. For example, You may need images, icons, animations, audio, video etc. while creating user interface. They are the resources we need to store somewhere in the application. Android has a separate and structured folder for these resources. They are stored in res folder in any android application.

Post a Comment