If you are using the Android operating system or want to program in this field, you should familiarize yourself with its components according to the development of Android applications. The main components of Android are the main elements of building an Android application. These components include Activity, Views, Services, and Content Providers.
Table of Contents
Activity
An activity represents a single page with a user interface. For example, an e-mail program might have an activity that displays a list of new e-mails, another activity for writing e-mails, and another activity for reading e-mails. Although these activities work together to create a cohesive user experience in the email program, they are independent of each other, so if the email program allows, another program can start any of these activities.
For example, a camera app can trigger an activity in an email app that creates a new email so the user can share a photo. If a program has more than one activity, one of them should be marked as the activity that is presented when the program is launched.
An activity is implemented as a subclass of the Activity class as follows:
{} public class MainActivity extends Activity
Now let’s see how to create an Activity. There are two ways to create activities: the first way, which is dynamic, uses Android Java programming, and the second way uses XML. The most commonly used method is to design activities using XML because it is easier. Also, by following this method, the codes related to the GUI or graphic environment are separated from the codes related to how the elements inside this graphic environment work. which are written in Java language can be separated from each other and with this method it becomes easier to debug the application.
services
A service is a general-purpose place to run programs in the background for various reasons. A service is a component that runs in the background to perform long-running operations or perform work for remote processes. A service does not provide a user interface. For example, a service may play music in the background while the user is in another application, or it may receive data over the network without blocking the user’s interaction with an activity, in which case Another activity can start the service and allow it to run or connect to it to interact with it. Two completely different services that have just started tell the system how to handle a program and keep it running until they are done. which can be synchronizing some data in the background or playing music even after the user leaves the application. Syncing data in the background or playing music is also included.
The service is implemented as follows:
{} public class MyService extends Service
Broadcast Receiver
A broadcast receiver is a component that enables a system to allow an application to respond to system-wide broadcast announcements. Because broadcast receivers are another well-defined input to the program, the system can deliver broadcasts even to programs that are not currently running.
So, for example, an application can schedule an alarm to send a notification to tell the user about an upcoming event, and by delivering that alarm to the application’s Broadcast Receiver, the application no longer needs to run until the alarm goes off and the alarm goes off. will be
Many broadcasts originate from the system, for example, a player reports that the screen is off, the battery is low, or a video has been taken. Applications can also initiate a broadcast, for example, an application notifies other applications that some data has been loaded onto the device and is available for them to use. Although broadcast receivers do not display a user interface, they may generate a status bar notification to alert the user when a broadcast event occurs, although a broadcast receiver is usually just a gateway to other components and has very little to do.
content providers
A content provider can manage shared application data sets that reside in the file system, SQLite database, the web, or any other persistent storage location that your application has access to. If the content provider allows, through the content provider other applications can search or change the data.
For example, the Android system provides a content provider that manages user contact information. Likewise, any application with the appropriate permissions can request a content provider such as ContactsContract.Data to read and write information about a specific person.
A content provider is implemented as a subclass of the Content Provider class and must implement a standard set of APIs that enable other applications to execute transactions.
Manifest file task
The main task of the manifest is to inform the system about the application components. To be able to start an application component, the system must know that this component exists by reading the application manifest file AndroidManifest.xml. Your application must introduce all its components to Android in this file, on the other hand, it also includes the permissions that the user must issue to install the application.
For example, an app asks permission to activate the camera.
Other components are used in the construction of the mentioned components, which include the following:
Fragments: represent part of the user interface in an activity.
views UI: elements that are displayed on the screen, including buttons, list forms, etc.
Layouts: represent hierarchies that control page layout and appearance of views.
Intents: connect components.
Resources: External elements, such as strings, constants, and drawable images.