Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the four building blocks of Android applications?

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces what are the four building blocks of Android application, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Android applications can save their data to files, SQL databases, or even any valid device, but only if they have a deep understanding of what Android applications are and how Android applications work.

For an Android application, it is organized by four building blocks as follows:

◆ Activity

◆ Intent Receiver

◆ Service

◆ Content Provider

However, not every Android application needs these four building blocks, which is not necessary, and sometimes we only need a few of these four to combine into our application.

Once we have identified which building blocks our application needs, we need to register a list of these building blocks in AndroidManifest.xml. This is a XML configuration file.

This configuration file is used to define the components of our application, the functions and requirements of the components, and so on. This configuration file is required for every Android application. For AndroidMainfest.xml 's Schema, refer to the documentation that came with the SDK package. Here are some descriptions of the four building blocks:

1 、 Activity

Activity is one of the most basic building blocks of Android. In applications, an activity is usually a separate screen. Each activity is implemented as a separate class. And inherits from the base class Activity. This activity class will display the user interface made up of several Views controls and respond to events. Most applications include multiple screens.

For example, a short message application will have a screen for displaying a contact list, a second screen for writing short messages, and a screen for browsing old short messages and making system settings. Every such screen is an activity. It is easy to navigate from one screen to another. In some applications, a screen may even return a value to the previous screen.

When a new screen opens, the previous screen will be paused and saved in the history stack. The user can return to the previous screen in the history stack. When the screen is no longer in use, it can also be removed from the history stack. By default.

Android will keep the running screen from the home screen to each application. Android uses the special class Intent to move from screen to screen. The Intent class is used to describe what an application will do. In the descriptive structure of Intent.

There are two most important parts: action and data corresponding to the action. Typical action types are: MAIN (activity's portal), VIEW, PICK, EDIT, and so on. The data corresponding to the action is expressed in the form of URI. For example: to check a person's contact information.

You need to create an intent with an action type of VIEW, and a URI that represents this person. A class related to it is called IntentFilter. As opposed to intent is a valid request to do something, an intent filter is used to describe which intent an activity (or Intent Receiver) can operate on.

An activity needs to declare an IntentFilter if it wants to display a person's contact information, and the IntentFilter needs to know how to handle the VIEW action and represent a person's URI. IntentFilter needs to be defined in AndroidManifest.xml.

Navigating from one screen to another is simple by parsing various intent. When navigating forward, activity will call the startActivity (Intent myIntent) method. The system then looks in the IntentFilter defined in all installed applications to find the activity corresponding to the Intent that best matches the myIntent.

When the new activity receives the notification from myIntent, it starts running. When the startActivity method is called, the action to parse the myIntent is triggered, and this mechanism provides two key benefits:

A, Activities can reuse a request in the form of Intent from other components

B, Activities can be replaced at any time by a new Activity with the same IntentFilter.

What are the four building blocks of Android applications are shared here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report