9.1 Operational status of four components
In addition to the Broadcastreceiver accident in the four components of Android, the other three components must be registered in the Androidmanifest.
In the invocation mode, Activity,service and broadcastreceiver need to use intent, and ContentProvider without the help of intent.
Activity is a display component that presents an interface directly to the user and can receive input from the user to interact with it.
A service is a computational component that performs a series of computational tasks in the background, requiring flexibility in both stopservice and Unbindservice to completely stop a service component.
Broadcastreceiver is a message-type component that is used to deliver messages between different components and even different applications.
Working process of 9.2 activity
There are several overloads of the StartActivity method, but they will eventually call the Startactivityforresult method.
Applicationthread is an internal class of Activitythread, which plays an important role in the activity initiation process.
In Activitymanagernative, the binder object of AMS is provided externally in a singleton mode, and Singleton is a single wrapper class that initializes the binder object by the Create method when it first calls its Get method.
The role of Checkstartactivityresult is to check the results of initiating activity, which throws an error message when an activity cannot be started correctly.
The order in which activity's initiation process passes between Activitystacksupervisor and Activitystack
Performlaunchactivity This method mainly accomplishes the following several things
1. Get the component information for the activity you want to start from the Activityclientrecord.
2. Use the instrumentation Newactivity method to create an activity object using the class loader.
3. Try to create the Application object by Loadedapk's Makeapplication method.
4. Create the Contextimpl object and perform some important data initialization through the activity's attach method.
5. Call the activity's OnCreate method
Working process of 9.3 service
The service is divided into two working states, one of which is the startup state, which is used primarily for background computing, and the other is the binding state, the interaction of the other components of the main user and service.
You can start a service by using the StartService method of the context.
9.3.1 Service Start-up process
Starting with Contextwrapper's startactivity.
AMS will mservices this object to complete the service follow-up process, the type of Mservices object is activeservices, to assist AMS for service management classes, including service start, bind and stop.
Handlecreateservice:
The first instance of the service is created through the ClassLoader.
Then create the Application object and call its oncreate.
The Contextimpl object is then created and the relationship between the two is established through the service's attach method.
Finally, the service's OnCreate method is called and the service object is stored in a list in Activitythread.
Binding Process for 9.3.2 service
The specific binding process of service is accomplished mainly through AMS, Bindservice method
AMS will call Activeservices's Bindservicelocked method ... Finally, the service instance is created and its OnCreate method is executed through Applicationthread.
Work Engineering of 9.4 Broadcastreceiver
One is the registration process of the broadcast, and the other is the sending and receiving process of the broadcast.
Registering statically in the Androidmanifest file
<receiver android:name= ". Myreceiver ">
<intent-filter>
<action android:name= "Com.example.receiver.LAUNCH" >
</intent-filter>
</receiver>
Registration process for 9.4.1 broadcast
Static Registration and dynamic registration
is the PMS (Packagemanagerservice) to complete the entire registration process.
The process of dynamic registration starts with the Contextwrapper Registerreceiver method.
Eventually, the remote Innerreceiver objects and Intentfilter objects are stored.
The sending and receiving process of 9.4.2 broadcast
When the broadcast is sent via the Send method, AMS looks for the matching broadcast recipients and sends the broadcast to them for processing.
Regular broadcasts, orderly broadcasts, and sticky broadcasts.
The broadcast sends a Sendbroadcast method that still starts at Contextwrapper. Give the matter to Contextimpl to deal with.
Within the broadcastintentlocked, the matching broadcast receiver is found based on the intent-filter and filtered by the conditions of some columns, eventually adding the broadcast recipients that meet the criteria to the broadcastqueue. The Broadcastqueue then sends the broadcast to the appropriate broadcast recipient.
The working process of 9.5 contentprovider
A content-sharing component that provides data through binder to other components and even other applications, and when the ContentProvider process is started, ContentProvider is started and published to AMs.
ContentProvider startup process:
The Nineth chapter: the working process of four components