Application Components

For building and developing applications, Application components are very important elements. They serve as the starting point for users or systems to start using an android application. There are four different types of components. Each component has its own role anddifferent life cycle.

The main four components of an Android application are:


1. Activity

Activity is a class, which is considered the user's entry point and represents a single screen. Messaging applications can have one activity that indicates a new notification, another activity that reads a message, and another activity that writes a new message.
Each activity is independent of the others. For example, the camera application can be launched in amessage application to send a message using real-time pictures. When you took a picture camera activitygets destroyed and the previous activity getsresumed.

To create a new Activity, you need to inherit the Activity class:

public class MyActivity extends Activity { 
//code 
}

2.Service

Service is a component that runs in the background and acts as an invisible worker in our application, constantly updating data sources and actions, and conveying intent, and performing tasks when the application is idle. An example of a service is that we can surf the Internet or use any other application while listening to music.

To create a Service, you need to inherit the Services class:

public class NewServiceextendsServices {
// code 
} 

3.Contentprovider

Content providers are components that enable applications to exchange data between multiple applications. It hides the detailed information of the database and can be used to read and write private application data that is not shared. In the absence of a content provider, it would be difficult to access data from other android apps.

For example, you might consider looking for contact information in your contact list, or you might want photos from a gallery that are also provided by content providers.
To create a Content Provider, you need to inherit ContentProvider class:

public class New_Provider extends ContentProvider {
// code 
} 


4. Broadcastreceiver

A broadcast receiver is a response from another application or the same system The components of the broadcast. You can also send the stream to an application that is not working. For example, notify the user when the battery is low. Android developers can use broadcast messages in applications or outside of normal operating procedures.
To create a Broadcast Receiver, you need to inherit BroadCastReceiver class:

public class New_broadcastextendsBroadcastReceiver {
//code
}

Additional Components

Some additional components of Android applications:

1. Intents

This is a structure used to route messages between applications to communicate between Android components. It is also used to exchange data between different activities, start new services and display a list of contacts in the ListView. Example: When the user decides to share an image, the camera application sends an intent to the operating system.

2. Widgets

Widgets are different types of broadcast receivers and are an important aspect of customizing the home screen. They display data and allow users to manipulate it. There are different types of widgets:

  1. Information widgets: These widgets display important information and track how the information varies over time. Example: A clock widget and a widget that displays weather information.
  2. Collection widgets: As the name suggests, collection widgets are a collection of the same type of information. They are used to view information and open item to view detailed information, such as call widget as you can hang up or accept calls outside of the call application.
  3. Control widgets: These widgets display functions, and users can activate them from the home screen without opening the application.Example: Pause and play a video outside the application.
  4. Hybrid widgets: These widgets combine the functions of the other three widgets. Example: The music player widget is a control widget, but it also informs the user which track is currently playing, so it is a combination of control and information, which is why it is called a hybrid widget.

3. Views

The View is responsible for drawing and handling events. These are rectangular elements on the display. Some views are TextView, Sliding button, EditText, ImageView, CheckBox, and ImageButton.

4. Notification

Alerts the user when the application is not displayed or in an inactive state. This warning flashes on the screen and then disappears. Example: A notification of a new incoming message is displayed on the screen.

5. Fragment

The Fragment is part of the entire user interface. Users can combine multiple fragments in one activity, and these fragments can be reused for multiple activities.Fragments usually contain views and view groups within them.

6. The Layout files

The layout is the structure of the user interface (i.e., what users see on their phone screen) in the application. The XML file provides different types of layouts for different screen types and determines which GUI components, actions, or fragments are included.

7. Application APK Files

Apk files are a package file format that contains program code, resources, and assets. The Android operating system uses APK files to install android apps and middleware.

8. Resources

Resources in Android are used to define images, text, and strings. Everything that is defined in the resource files can beinvoked in the application code.

Please check out our next resource article to learn more about Android resources.