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 important components of Android application development?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article to share with you is about the four important components of Android application development are what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

51CTO introduced "Android SNK preliminary exploration", Android development must understand building blocks, Android applications are composed of four important components, these four building blocks are as follows:

◆Activity

◆Intent Receiver

◆Service

◆Content Provider

51CTO Recommended Topic: Android Development Application Detailed Explanation

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

Once we know what building blocks our application needs, we need to register a list of those building blocks in AndroidManifest.xml. This is an XML configuration file that defines the components of our application, their capabilities, requirements, etc. This profile is required for every Android app. For the Schema of AndroidMaintest.xml, refer to the documentation that comes with the SDK package. Below, we describe the four building blocks:

1、Activity

Activity is one of the most basic Android building blocks, and in an app, an activity is usually a separate screen. Each activity is implemented as a separate class and inherits from the Activity base class. The activity class displays a user interface consisting of several Views controls and responds to events. Most applications have multiple screens. For example, an SMS application will have one screen for displaying a contact list, a second screen for writing SMS messages, and screens for browsing old SMS messages and system settings. Each of these screens is an activity. Navigating from one screen to another is easy. In some applications, one screen even returns a value to the previous screen.

When a new screen opens, the previous screen is paused and saved in the history stack. The user can return to the previous screen in the history stack. It can also be removed from the history stack when the screen is no longer in use. By default, Android will keep running screens from the home screen to each app.

Android uses a special class called Intent to move between screens. The Intent class describes what an application will do. In the Intent description structure, there are two most important parts: action and data corresponding to action. Typical action types are MAIN (activity portal), VIEW, PICK, EDIT, etc. The data corresponding to the action is represented in the form of URI. For example: To view a person's contact information, you need to create an intent with action type VIEW and a URI representing the person.

A related class is called IntentFilter. Whereas an intent is a valid request to do something, an intent filter describes which intents an activity (or Intent Receiver) can operate on. An activity If you want to display a person's contact information, you need to declare an IntentFilter. This IntentFilter needs to know how to handle the VIEW action and the URI representing a person. IntentFilter needs to be defined in AndroidManifest.xml.

Navigating from one screen to another is easy by parsing intents. When navigating forward, the activity calls the startActivity(Intent myIntent) method. The system then searches through IntentFilters defined in all installed applications to find the activity corresponding to the Intent that best matches myIntent. The new activity receives the notification of myIntent and starts running. When the startActivity method is invoked, it triggers an action to resolve myIntent. This mechanism provides two key benefits:

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

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

2、Intent Receiver

When you want your app to respond to an external event (such as when a phone call comes in, or when a data network is available, or when it's evening), you can use an Intent Receiver. Although the Intent Receiver uses the Notification Manager to notify the user when an event of interest occurs, it does not generate a UI. Intent Receiver is registered in AndroidManifest.xml, but can also be registered in code using Context.registerReceiver(). When an intent receiver is triggered, your app doesn't have to call intent receiver for the request, the system launches your app when needed. Applications can also broadcast their own intent receivers to other applications by using Context.broadcastIntent().

3、Service

A Service is a long-lived program with no user interface. A good example would be a media player playing songs from a playlist. In a media player app, there should be multiple activities that allow users to select songs and play them. However, there is no activity for music playback, because users will naturally assume that music should still be playing when navigating to other screens. In this example, the media player activity uses Context.startService() to start a service that keeps music playing in the background. At the same time, the system will keep this service running until the service runs out. Alternatively, we can connect to a service by using the Context.bindService() method (which will start the service if it is not already running). When connected to a service, we can also communicate with it through the interfaces provided by the service. In the media player example, we can pause, replay, and so on.

4、Content Provider

Applications can save their data to files, SQL databases, or even any valid device. Content Providers are useful when you want to share your app data with other apps. A Content Provider class implements a standard set of methods that enable other applications to save or read the various data types handled by this Content Provider.

The above is what the four important components of Android application development are, Xiaobian believes that some knowledge points may be what we see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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