Understanding the working process of the four major components from the source code perspective-Android development art exploration notes

Source: Internet
Author: User

Understanding the working process of the four major components from the source code perspective-Android development art exploration notes

The system encapsulates the process of the four major components to a large extent, and does not need to understand the underlying working principles in daily development. So what is the significance of studying these principles?

If you want to further develop the technology, it is essential to understand the operating principles of some systems and the technical capabilities necessary for developers to grow into senior engineers in the future. Android, as an excellent Linux-based operating system, must have a lot of points worth learning internally. It is of great benefit to improve developers' internal strength through studying the Android operating system. If you are engaged in Android Rom development, there is nothing to say. Check the source code.

This article focuses on the analysis of the working processes of the four major components. By analyzing their working processes, we can understand the internal operating mechanism of the system and deepen our understanding of the overall Android system structure.

There are too many source codes related to Android, and it is too cumbersome to paste them all. Therefore, the entire process is easier to understand by using the UML diagram of amurocrash.

The main function of the running status Activity of the four major components is to display an interface and interact with users. It plays a role in the foreground interface. A Service is a computing component used to execute a series of computing tasks in the background. Service has two statuses: startup and binding. When the Service is started, it does not need to interact with the outside world. The Bound Service can easily communicate with the Service component. The Service is running in the main thread.Therefore, the time-consuming background computing still needs to be completed in a separate thread. You can use either stopService or unBindService to stop a Service component. BroadcastReceiver is a message component used to transmit messages between different components and even different applications. Broadcast registration can be static or dynamic. registerReceiver () is used for implementation. Contex is not required. unRegisterReceiver () to cancel broadcasting. This method must be enabled before registration. Static registration is performed in the AndroidManifest file, which will be parsed by the system during application installation, you do not need to start the application to receive broadcasts. The matching process is described through. ContentProvider is a shared component used to share data with other components and other applications. It maintains a data set internally and needs to add, delete, modify, and query operations. This data set can be implemented through databases or other types, such as List and Map. Note that thread synchronization should be processed for addition, deletion, modification, and query. These methods are called in the Binder thread pool. In addition, ContentProvider does not need to be stopped manually. Activity Process

Note <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Examples/examples/LXEZ2V0t723qMqxu + examples/J0tS/examples/O1xLS0vai5/bPM0rvR + examples/examples + samples + zb/example "service work Process "> Service work process

Startup Process

Binding Process

Note
-Service has two statuses: startup and binding. The two statuses can coexist.

BroadcastReceiver's Working Process

BroadcastReceiver processes include the broadcast registration process, broadcast sending and receiving process.
Dynamic Registration

Send and receive

Note:

Static registration is completed by PackageManagerService (PMS) during application installation. In addition to broadcasting, all the other three components are parsed and registered by PMS during application installation. There are several types of broadcast sending: normal broadcast, ordered broadcast, and viscous broadcast. Ordered broadcast and viscous broadcast have different characteristics than normal broadcast, but the sending and receiving processes are similar. FLAG_INCLUDE_STOPPED_PACKAGES: the broadcast is sent to the stopped application. The FLAG_EXCLUDE_STOPPED_PACKAGES broadcast is not sent to the stopped application starting from Android 3.1. The stopped application cannot receive the boot broadcast. ContentProvider

Startup Process

When the process of ContentProvider is started, it will be started and published to AMS at the same time. Note that at this time, its onCreate must be first executed in the onCreate Application, this is a rare phenomenon among the four major components. The Start entry is the main method of ActivityThread. The main method creates an ActivityThread instance and a message queue of the main thread. In the attach method, the attachApplication method of AMS is called remotely, and ApplicationThread is provided for communication with AMS. The attachApplication method calls back the handleBindApplication of ActivityThread through the bindApplication method and H. This method creates an Application, loads ContentProvider, and calls back the onCreate method of the Application. The multiprocess attribute of ContentProvider determines whether ContentProvider is a singleton (when false). It is generally used as a singleton. The specific class of ontentResolver is ApplicationContentResolver. When the process of ContentProvider is not started, the first access to it will trigger the creation of ContentProvider and process startup.

Query Process

The insert, delete, and update methods are similar. We will not analyze them here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.