Activity is an Android ApplicationProgramAllows you to create a user interface on it, and provides APIs for users to process events, such as onkeyevent and ontouchevent. And maintain the application lifecycle. Activity itself is a huge carrier, which can be understood as the carrier of the application. If there is a wooden activity, the android application will not be able to run. Activitymanagerservice is responsible for maintaining the Instance Object of the activity and maintaining its status information based on the running status.
When we call the setcontentview method of acitivity, it actually calls the setcontentview method of the window object. Therefore, we can see that the interface painting in the activity is actually done by the window object. To draw a class chart, we can see that activity aggregates a window object.
In this method, first create a decorview. decorview is a class that expands framelayout and is the root view of all windows. The setconctentview we call in the activity is put in the decorview. This is the aggregation relationship of the class graph as follows:
Activity ---> window ---> decorview
After an activity is created, the system calls its attach method, adds it to activitythread, and creates a window object in the attach method. The window object is an abstract class. Note that when creating a window object, you can create a decor object. The user calls setcontentview in the activity and then calls setcontentview of window. Then, the user checks whether decorview exists. If not, the user creates a decorview object and adds the user's view to decorview.
In activitythread, WM is called. addview (decor, L); add it to the mviews Of The Window Manager Proxy, and create a viewroot for the decor view. viewroot is responsible for coordinating the direct drawing and event processing between the decorview and windowmanager. Simply put, decorview is the root of all views on the client. The Window Manager Proxy creates a viewroot for this decorview and processes the Window Manager service.
Let's take a look at the implementation of decorview, which is an internal class of phonewindow. The implementation is very simple. It will contain a gray title bar by default, and a blank area under the title bar will be included to place the user view and pass the event when the user calls setcontentview.