The relationship between view, Window, Activity, Windowmanager,viewroot in Android

Source: Internet
Author: User

(1) View: The main UI component that represents a rectangular area on the screen.



(2) Window: Represents a form that does not necessarily have a large screen size and can be very large or very small;
                          It includes a view The layout parameters of the tree and form.
                  The root view of         view tree is available through Getdecorview. You can also set the content View of the window.

(3) activity:activity includes a window. The window is called in the activity's attach method by calling
                       Policymanager.makenewwindo Create

(4) WindowManager: a interface. Inherit from Viewmanager.

There is a implementation

(5) Class:android.view.WindowManagerImpl

In fact WindowManager is not the form manager of the entire system, but the form manager of the application process. The system global Form manager executes in the systemserver process and is a service.

Viewroot interacts with the global Forms manager through the Iwindowsession interface.

When you add a view to WindowManager. Windowmanagerimpl Create a viewroot to manage the root view of the form. and pass the view to Viewroot through the Viewroot.setview method.

Viewroot is used to manage the root view of the form and interact with the global window manger. There is a nested class:w in Viewroot. W is a binder subclass that receives various messages from the Global window manager, such as keystroke messages, touch messages, and so on. Viewroot has a member of the W type Mwindow,viewroot creates a W instance in constructor and assigns a value to Mwindow. Viewroot is a subclass of handler. W will pass the message to Viewroot via Looper.

Viewroot the Mwindow to Swindowsession in the Setview method.



Activitythread.java Call Wm.addview (decor, l); add it to Window Manager
Proxy in the mviews. Create a viewroot,viewroot for this decor view at the same time coordinates decor view with window
Manager direct drawing, event processing.

In Viewroot, Iwindowsession and Iwindow were used to deal with Window Manger and receive window
The message that the manager sent over. After the message is transmitted, Viewroot is distributed to decor view and then decor view.



in summary, each form corresponds to a Window object, a root view, and a Viewroot object. To create a form, you can call
The AddView method of WindowManager. View as a parameter is the root view that is displayed on the form

Generally speaking, activity is a visual human-computer interface.
Each activity has a default window. Generally speaking. This window is full-screen, and of course there are exceptions. For example, Dialog's window is not full-screen. The activity can also take advantage of Windows other than the default window. For example, a dialog dialog box pops up.

6 i8 J ' I ' B + v. f% r   the content visible in the
window is a layer of view. The view in window is set in by Setcontentview this interface, and this contentview is the view at the very root of the window. < br>
for the screen display, the whole activity is actually a window, so why do you say that? The

is in the Activityattach function. There is such a sentence Mwindow = Policymanager.makenewwindow (this); The

is associated with the Activiyt window. The real connection is Phonewindow.

The object shown in this window is view (activity is a logical thing, add life cycle management, etc.). The details are also view. And the implementation of the activation activity is also in the window to add view, to the window to add view, is by calling WindowManager (Windowmanagerimpl). AddView () to achieve.



Why is it possible to say so?

See public void Setcontentview (int layoutresid) {
GetWindow (). Setcontentview (LAYOUTRESID);
}


In the AddView. Creates a viewroot for each view (this is a logical thing to be responsible for the event handling and logic processing of the view. and Windowsmanagerservice), and in Windowmanagerimpl, an array of viewroot is maintained.

The Viewroot.setview () will eventually be called, and the view will be displayed in the Setview. In the realization of Setview. Will call Session.add () to AddWindow, through this method. Viewroot and Windowmanagerservice are linked (for example, distributing events), and PHONEWINDOWMANAGER.PREPAREADDWINDOWLW () is called in this method.

This is just a vague concept. There is still detail to be done, and I will continue to work hard. Let's say you feel like this is going to happen. You have to give me the top, I am not easy. It's very hard.



The relationship between view, Window, Activity, Windowmanager,viewroot in Android

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.