The secret of the unimaginable success of Android Applications is hidden inside them. The essential building blocks, more commonly known as Android Components, of an Android application are the key to the great outcomes. Basically, the Android Components of an application enable it to have numerous qualities to make it highly competent and efficient.
Each of all the Android Components has a specific purpose, which is incredibly crucial for a great app performance. Also, the application manifest file or the AndroidManifest.xml file is responsible for loosely coupling the Android Components. Among other duties, this file describes all the Android Components and how one of them interacts with the rest.
To make it easier to understand, we will divide the Android Components into two categories:
There are four main Android Components that can be used within an app. These components are:
Basically, an activity represents a single screen with a UI (User Interface). In other words, an activity of an app performs actions on the screen. Therefore, an Android activity is one screen of a UI of an Android app. For better understanding, consider an email app, such as Gmail. Gmail has one activity that shows a list of emails, another activity for composing an email and so on.
Many of you must have noticed that an Android app may contain one or more activities or screens, each with some changes in the UI. One of these activities is known as the main activity that is displayed when the application is launched. After opening the main activity, the app may make it possible for the user to open other activities.
To sum it up, an activity dictates the UI and manages all the interactions a user has with the smart phone screen.
In Android, services are processes taking place in the background. These processes can be executed on an Android device even when no application is visible. For this reason, services do not need any UI. Android services can be used for many operations. For instance, a service could back up data every hour. Also, a service might play music in the background when the user is working on another application. An Android service could even check a remote server for updates. It may even fetch data over the network without interrupting a user’s interaction with an activity.
In a nutshell, services in Android manage background operations related to an application.
In an Android app, a broadcast receiver only responds to messages. These messages may either come from a different application or from the system.
To give you an idea, an application may initiate a broadcast in order to tell a second application that some data has been downloaded to the device and that the second application can now use the data. The second application, in this example, is the broadcast receiver that intercepts this communication and takes an appropriate action.
An Android app developer implements a broadcast receiver as a subclass of BroadcastReceiver class. Also, in a broadcast receiver, each message is broadcasted as an Intent object.
In short, a broadcast receiver is responsible for handling the communication between the Android operating system and the applications.
The last of the main Android Components is the content provider, which transfers data from one application to other applications on request. These requests are managed by Content Resolver class methods. The said data is stored in the database, file system or anywhere else.
To implement a content provider, an Android app developer uses it as a subclass of Content Provider class. Another important point about content providers is that a standard set of APIs must be implemented to enable other apps to perform transactions.
Briefly, one can say that content providers handle data and issues associated with data management.
Generally, there are six additional Android Components. Basically, these additional Android Components are used to build the main Android Components, their logic and the wiring between them. These additional components are:
In Android, intents are small objects or messages that an activity passes to the operating system. This is done so that the activity can tell the operating system that a different action or activity is required. For example, when a user chooses to share a photo through a photo app, the app sends an intent to the operating. This intent carries the description of the sharing action. The Android system, then, opens a second application that can share the photo to perform the action.
In simpler words, intents are messages that wire application components together.
A fragment, in an Android app, is literally a fragment of the total UI in an activity. Therefore, a fragment only takes up part of the screen, unlike an activity. A fragment has to be used inside an activity, and one fragment can be used within different activities. Typically, a fragment contains Views and ViewGroups inside it.
Shortly, a fragment represents a portion of UI in an activity.
Layouts are nothing but view hierarchies the handle appearance of views and screen format. In Android development, layout and contents of fragments, ViewGroups and activities are defined by using XML files. These layout XML files are used to specify the GUI (Graphical User Interface) elements a fragment or activity would have. Besides that, these files are also used to specify the style (size, padding, etc.) of the GUI elements.
Shortly, a fragment represents a portion of UI in an activity.
Basically, Android GUI components are of three types: Activities, Views and View Groups. Views refer to the UI components, such as list forms and buttons, which are drawn on the screen. Other the other hand, a View Group collects a number of Views together. Both Views and View Groups are embedded by an activity or a fragment. If they are nested inside a fragment, the fragment, as we mentioned earlier, would be embedded by an activity.
In Android, resources refer to external elements, such as images, constants and strings, which an application uses. However, these elements are not in the form of any programming language source code. UI layouts are a type of Android resource. These layouts are created by using a structured tool, like the GUI builder of an IDE, or by hand in XML form. Sometimes, the UI elements work in all kinds of devices. Other times, they need to be tailored for different types of devices. For that, a developer needs to put the resources into resource sets that specify the circumstances under which the resources should be used.
The configuration file of an application is referred to as Manifest file, common written as AndroidManifest.xml file. In the manifest of an Android application, there is information about the app package. This information includes components of the app, such as services, content providers, broadcast receivers and activities.
Apart from that, the manifest is responsible for protecting the app by providing permissions to access any protected parts. Also, it enlists the instrumentation classes that provide profiling and other information. Furthermore, manifest defines the Android API that the application will be using.