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 components of android

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

Share

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

What are the four major components of android, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Android has four major components: Activity, Service, Broadcast Receiver, and Content Provider

1 、 activity

An Activity is usually a separate screen (window).

(2) Activity communicate with each other through Intent.

(3) every Activity in the android application must be declared in the AndroidManifest.xml configuration file, otherwise the Activity will not be recognized or executed by the system.

2 、 service

(1) service is used to complete user-specified operations in the background. There are two types of service:

● started: when an application component, such as activity, calls the startService () method to start the service, the service is in the started state.

● bound: when the application component calls the bindService () method to bind to the service, the service is in the bound state.

(2) the difference between startService () and bindService ():

The ● started service is started by other components calling the startService () method, which causes the service's onStartCommand () method to be called. When a service is in started state, its life cycle is independent of the component that started it and can run indefinitely in the background, even if the component that started the service has been destroyed. Therefore, the service needs to be stopped by calling the stopSelf () method after the task is completed, or by another component calling the stopService () method.

● uses the bindService () method to enable the service, and the caller is bound to the service. Once the caller exits, the service is terminated, which has the characteristic of "not living at the same time, but dying at the same time".

(3) developers need to declare all service in the application configuration file and use tags.

(4) Service usually runs in the background, and it generally does not need to interact with the user, so the Service component has no graphical user interface. The Service component needs to inherit the Service base class. Service components are usually used to provide background services for other components or to monitor the running status of other components.

3 、 content provider

(1) the android platform provides Content Provider to provide a specified dataset of one application to other applications. Other applications can obtain or store data from the content provider through the ContentResolver class.

(2) content providers are needed only if you need to share data among multiple applications. For example, address book data is used by multiple applications and must be stored in a content provider. Its advantage is to unify the way to access data.

(3) data sharing is realized by ContentProvider. ContentProvider is used to save and retrieve data and make it visible to all applications. This is the only way to share data between different applications because android does not provide a common storage area for all applications to access.

(4) developers do not directly use objects of the ContentProvider class, most of them operate on ContentProvider through ContentResolver objects.

(5) ContentProvider uses URI to uniquely identify its data set. Here URI is prefixed with content://, indicating that the data is managed by ContentProvider.

4 、 broadcast receiver

(1) your application can use it to filter external events and only receive and respond to external events of interest (such as when a phone call comes in, or when a data network is available). The broadcast receiver has no user interface. However, they can launch an activity or serice to respond to the information they receive, or use NotificationManager to notify the user. Notifications can attract users' attention in many ways, such as flashing backlights, vibrating, playing sound, and so on. Generally speaking, you can put a persistent icon on the status bar so that the user can open it and get the message.

(2) there are two ways to register the broadcast receiver, namely, dynamic registration of the program and static registration in the AndroidManifest file.

(3) dynamic registration of broadcast receivers is characterized by the fact that when the Activity used for registration is turned off, the broadcast becomes invalid. Static registration does not need to worry about whether the broadcast receiver is turned off, as long as the device is turned on, the broadcast receiver is also open.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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