Relationship between window, view, and activity in Android

Source: Internet
Author: User

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.

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.