Note: The following content is based on Android API Version 27 (Android 8.1) Linux Kernel 3.18.0

summary

Activity, Dialog, PopupWindow, and Toast represent the four typical Window forms.

  • The Window type of an Activity is TYPE_APPLICATION, which has a unique AppWindowToken corresponding to it in WMS.

  • The Window type of a Dialog is also TYPE_APPLICATION(Dialog is not a child Window), and a Dialog shares an AppWindowToken with its Activity.

  • PopupWindow’s Window type is TYPE_APPLICATION_PANEL. TYPE_APPLICATION_PANEL is a child Window. PopupWindow shares an AppWindowToken with its Activity.

  • Toast the Window type is TYPE_TOAST, TYPE_TOAST is one of the system Window, Toast token is founded by NotificationManagerService, Toast each corresponding to a token of my own, Toast’s token in WMS corresponds to Windows Token.

PhoneWindow/DecorView/ViewRootImpl

PhoneWindow contains a DecorView. The Activity’s Content view is a child of a DecorView, which is the root view of the Content View after applying the template (window style).

A DecorView corresponds to a ViewRootImpl, which is a virtual root View, not a View. The ViewRootImpl handles update requests from the View tree, communicates with the WMS, and dispatts input events.

Both the Activity and Dialog correspond to a PhoneWindow object. PopupWindow and Toast have no corresponding PhoneWindow, Activity/Dialog has a DecorView because it has a PhoneWindow, The DecorView can send input events to the Activity/Dialog via window.callback. PopupWindow/Toast is a View that uses a ViewGroup as its window, so PopupWindow/Toast itself does not have the ability to get input events. Input events are sent directly to the View tree. Since PopupWindow/Toast is also a window added via WindowManagerImpl, they all have a corresponding View wrootimPL and thus have the ability to communicate with WMS and dispatch events.

The Activity/Dialog/PopupWindow/Toast with WindowState

The Activity/Dialog/PopupWindow/Toast in the WMS has a corresponding WindowState, just the Activity/Dialog/PopupWindow WindowState belong to the same AppWindowToken, That is, the Activity’s token, while Toast’s WindowState is its own Unique WindowToken.