Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Android app components


May 21, 2021 Android


Table of contents


Android app components

The application component is the basic building block of an Android application. T hese components are loosely coupled by the application manifest file. The Android Manifest .xml describes each component of the application and how they interact.

Here are four main components you can use in your Android app.

Component Describe
Activities Describes the UI and handles the user's interaction with the machine screen.
Services Handle background operations associated with the application.
Broadcast Receivers Handle communication between the Android operating system and the application.
Content Providers Dealing with data and database management issues.

Activities

An activity identifies a single screen with a user interface. F or example, a mail application can contain an activity to display a new mailing list, another activity to write a message, and another activity to read a message. When an application has one more activity, one of them is marked as displayed when the application starts.

An activity is a sub-class of the Activity class, as follows:

public class MainActivity extends Activity {

}

Services

A service is a component that runs in the background and performs long operations. For example, a service can be a user playing music in the background while using a different program, or getting data over the network during an activity without blocking user interaction.

A service is a sub-class of a service class, as follows:

public class MyService extends Service {

}

Broadcast Receivers

The broadcast receiver simply responds to broadcast messages from other applications or systems. F or example, an application can initiate a broadcast to let other applications guide that some data has been downloaded to the device and can be used by them. The broadcast receiver therefore intercepts these communications and takes appropriate action.

The broadcast receiver is a sub-class of the BroadcastReceiver class, and each message is broadcast as an Intent object.

public class MyReceiver  extends  BroadcastReceiver {

}

Content Providers

The content provider component provides data from one application to another by requesting it. T hese requests are handled by the methods of the ContentResolver class. This data can be stored on a file system, database, or elsewhere.

The content provider is a sub-class of the ContentProvider class and implements a standard set of APIs for other applications to perform transactions.

public class MyContentProvider extends  ContentProvider {

}

We will cover the application components in separate sections through the details of these labels.

The attachment component

There are some attachment components for the entities mentioned above, the logic between them, and the construction of the wires between them. These components are as follows:

Component Describe
Fragments Represents an action or part of the user interface in an activity.
Views UI elements drawn on the screen, including buttons, lists, and so on.
Layouts Control the screen format to show the view's appearance of the view's inheritance.
Intents Messages between components are wired.
Resources External elements, such as string resources, constant resources, picture resources, and so on.
Manifest The profile of the application.