Android Basics: Application Components

Android Basics: Application Components

Application components are the basic building blocks of an Android application. These components are loosely coupled. The application manifest file AndroidManifest.xml describes each component of the application and how they interact with each other.

There are four main components that can be used in an Android application:

Components describe
Activities They determine the user interface and handle user interaction, the smartphone screen
Services They handle background processing related to the application.
Broadcast Receivers They handle the communication between the Android operating system and applications.
Content Providers They deal with data and database management issues.

Activities

An activity represents a single user interface on the screen. For example, an email application might have one activity that displays a list of new emails, another activity for composing emails, and another activity for reading emails. If the application has more than one activity, then one of them should be marked as the activity presented when the application is launched.

It is implemented as a subclass of the Activity class as follows:

  1. public   class MainActivity extends Activity {
  2.  
  3. }

Services

A service is a component that runs in the background to perform long-running operations. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking the user from interacting with the activity.

Implementing a service as a subclass of a service class is as follows:

  1. public   class MyService extends Service {
  2.  
  3. }

Broadcast Receiver

Broadcast receivers simply respond to broadcast messages from other applications or from the system. For example, an application can also initiate a broadcast to let other applications know that some data has been downloaded to the device and is available for them to use, so it is the broadcast receiver that will intercept this communication and take appropriate action.

Broadcast receivers are implemented as subclasses of the BroadcastReceiver class, and each message is broadcast as an Intent object.

  1. public   class MyReceiver extends BroadcastReceiver {
  2.  
  3. }

Content Provider

Content provider components provide data from one application to other upon request. Such requests are handled by methods of the ContentResolver class. The data can be stored in the file system, a database or elsewhere.

Content providers implement subclasses of the ContentProvider class and must implement a standard set of APIs that enable other applications to perform transactions.

  1. public   class MyContentProvider extends ContentProvider {
  2.  
  3. }

We will cover the details of the application components through these tags, also in separate chapters.

Add-ons

Additional components can be used to construct the above entities, their logic and the connections between them. These components include:

Components describe
Fragments Represents a behavior or part of the user interface within an activity.
Views Draws on-screen UI elements like buttons, list forms etc.
Layouts View hierarchy, control screen format and appearance views.
Intents Messages wire components together.
Resources External elements, such as strings, constants, and drawable images.
Manifest The configuration file for the application.

<<:  Apple Swift language open source project selection summary

>>:  Apple to launch dedicated app for Apple Watch

Recommend

Global annotation and graffiti

Ô´Âë¼ò½é ¿ ÉÒÔʵÏÖÈ«¾ÖÅú×¢£¬ÔÚÈκνçÃ涼¿ ÉÒÔ½«Åú...

A brief analysis of the six product and operation concepts implied by "Dangal"

Last weekend, I took advantage of my free time to...

Common problems and optimization strategies for mobile networks

When we start to pay attention to the user experi...

Overseas video marketing promotion: YouTube influencer marketing guide!

YouTube is quickly becoming one of the most popul...

Carcinogenic? Loss of nutrients? Air fryers are in trouble...

◎ Comprehensive report by Wang Yu of Science and ...

Long-term marketing strategy!

In the past, when brands were doing marketing pro...

From ad images to landing pages, 14 tips to improve conversions

This article is a summary of the book "The B...