Components of Android Application

This tutorial will make you understand what an android application is and the various components that make up an android application. Four components are essential for any Android-based application. Namely,

1. Activities

2. Services

3. Broadcast Receivers

4. Content Providers

This article will help you understand each component in detail and implement those components in your android studio.

What is an Android Application?

Android application is software that can freely run on any android device and performs several tasks. An Android Application is built with any of the following programming languages:

  • Java
  • Kotlin
  • C++

You are usually recommended to go ahead with Android Studio and choose any of the above programming languages for developing android applications.

An android application comprises four essential components and some additional components. The four components serve a specific purpose and have a specific lifecycle. They define a path for both user and system to how they can start or leave an application.

Components of Android Application

1. Android Activity

Activity is the single screen that is available to any user whenever he starts the application. This screen allows the user to interact with his application. There can be several such screens in one application.

Every activity consists of UI elements that help the user find out the task he wants to perform. Each activity has a specific lifecycle and is independent of other activities.

Suppose you see the first activity: the Chats whenever you open your messaging application(Ex: Whatsapp). Then, when you try to chat with someone, you move to another activity.

For example, suppose you wish to capture a picture and send it to your friend. For this, you shift from your WhatsApp activity to Camera Activity. It doesn’t imply that your WhatsApp activity is destroyed, but it gets paused when capturing the picture.

These all things are managed by the Activity Manager, and it takes care of which activities to start, pause or destroy. We will see the Activity Lifecycle in detail in further articles.

Code Implementation is as follows:

class MainActivity : AppCompatActivity()
{
  //Code
}

2. Android Services

Services are the processes that run in the background and do not have any user interface for the user to interact. It simply runs in the background and performs the tasks. It doesn’t matter whether the application is active or not; its services may be active. Services are a beneficial component and allow the user to perform various tasks like music playback, notification triggering, warnings, etc.

Suppose, for example, you kept the music on your music application and then went out of that application. Even yet, the background music continues to play.

Another ubiquitous example is your messaging app. Even if your messaging app is not active, you still receive notifications for any new messages coming to your device.

For implementing Services in android, you need to create a sub-class from the “Service” Class.

Code Implementation:

class ServiceName : Service() 
{
  //Your Code
}

3. Android Content Providers

Content Providers acts as a medium to various application to communicate with each other. It manages and looks over the application data and accesses the SQLite Database. However, it provides only exclusive data to the application user and does not allow you to access the other application data until granted.

All the seeking of data is done through the content provider itself. Whenever you require to access data from other applications, the content provider seeks permission from the user to access the data to the other application.

One typical example which you often notice is your gallery. Whenever any application needs to access some pictures from the gallery, it seeks your permission, and the content provider provides you with the required content.

Another ubiquitous example is your payments application which accesses your contacts to show who is there in your contacts to exchange money.

For implementing Content Provider in Android, you need to create a sub-class from the “ContentProvider” class.

Code Implementation:

class contentProviderName : ContentProvider() 
{
  override fun onCreate(): Boolean 
    {
      //Your Code
    }
}

4. Android Broadcast Receivers

Broadcast Receivers’ task is to receive any kind of intents from other applications. They respond to such intents with some behavior. Usually, broadcast receivers help to notify users of any process or application. They can notify the user either through notification, status bar, or even the user’s application(if active).

It’s not always necessary for your applications to be active to receive some notifications. Most of the time, these broadcasts are system originated and didn’t require the app’s user interface.

The most common example is your alarm application. Whenever you keep an alarm, you leave that application or simple terms, close that application. Still, at a particular time, you receive the notification.

Another pervasive example is your low battery reminders. Whenever your device has insufficient charge left, your device notifies you to keep charge or on battery saver mode.

These all happen because of the presence of broadcast receivers. It helps the system and the user’s applications to communicate.

For implementing Broadcast Receivers in android, you need to create a sub-class from the “BroadcastReceiver” class. Each broadcast is made through an “Intent” object.

For Example

class MyReceiver : BroadcastReceiver() 
{
 
    override fun onReceive(context: Context, intent: Intent) 
    {
        //Your Code
    }
}

Additional Components of Android App Development

Apart from the above, several other additional components are a part of an Android App:

1. Intents

Intents are a powerful component in any android application. It allows various applications and various activities to communicate with each other. It carries information of which activity shall be going next or which activity to stop or destroy. We even use intent to transfer data from one activity to another.

Intent objects are also used to send or receive broadcasts generated by the system.

For example: Whenever you click on the share button on your device, then the device prompts you with a list of applications through which you want to share the file.

2. Widgets

Widgets are a designing and customization component. Whenever you see your device’s home screen, you can find several widgets like clock, weather, etc. These widgets allow you to change the appearance of your home screen and even allow easy access to some often required stuff.

Following are the types of widgets which we very often see in any device:

a. Control Widget

It allows you to control your application through the widget. For example, your music players provide you a customized widget to pause, play, or stop the music without opening the application.

b. Information Widget

There are several information widgets such as time, date, weather, etc. It allows you to keep track of the required information.

c. Collection Widget

It shows you all your recent activities and provides you with faster access to which applications you might often use.
For example, if we recently used a phone or WhatsApp, it consists of these two applications.

d. Hybrid Widget

It’s a widget having the features of all the above widgets. For example, you can find all your recent apps, weather data, news feeds, and even still implemented music controllers to play or pause your music in this widget.

3. Views

Views are the components that are often used for designing and event handling purposes. Thus, views are part of both designing and coding. Using the views, we can describe how an element will behave or interact with the user.
There are several views in android. The most common of them are as follows:

a. EditText – used to take user inputs.

b. ImageView – used to display images.

c. Button – decide which event to perform by pressing the button.

d. CheckBox – selecting multiple options.

e. ImageButton – same as a button but has an image along with it.

f. Recycler View – It’s like a list displaying multiple data in the desired layout.

g. Nested Scroll View – allows the user to scroll horizontally or vertically.

h. Radio Button – allows the user to select only one option from the available.

i. Text View – displays text on your layout.

4. Notifications

It alerts the user of any update or any new announcement by the application providers. Notification can come on both foreground or background of the app. So even if the app is inactive, you still would receive a notification.
Using the Firebase Cloud Messaging tools, the application owners can even send push notifications on your device, which can be related to any promotion or any critical updates.

For example: Whenever someone messages you on your messaging application, then immediately you receive a notification.

Another example can be Flipkart sending notifications to its user, inviting them to the new upcoming sale.

5. Fragments

Fragments allow you to provide multiple functionalities by creating a single activity. Using fragments, you can do several tasks on the same activity itself. Fragments are reusable and can be used for various activities if required. The fragment is made of Views and View Pager.

For example: In WhatsApp, you can see that there is an activity that contains chat, status, and call as fragments. Using the same activity, you can even chat, keep status or call someone.

6. XML File

XML file makes up the layout for any android application. Using XML, we can create various designs or layouts for our application. XML even allows us to transfer data from the database to our layout file.

7. Resources

Resources store several things in Android. Whether you need a particular font style, image, colors, animations, or strings, all of these are stored in resources. Resources also allow you to put vector images in your android application.

8. APK Build

After the development is done, you can combine your code, resources, and files in a one-unit called APK(Android Application Package). This package can be installed on your device by the Package Manager, and then the user can use that application.

Summary

Through this article, you understood the several components that contribute to developing an android application and act as an entry and exit point for any android application. You also saw an example for each component and how these components are implemented in Android. Further, you will see the detailed implementation of each of these components.