Window management is an important component to learn in order to master Android OS development.
Android window management comprises of three components Window Window Manager and Window Manager Service.
You can imagine window management as the relationship between an employee, a manager and a boss.
Window is the employee.
Window manager is the manager who manages this employee and window manager service is the ultimate boss
and the Window Manager Service instructs the window manager to run the APIs.
So let's dig deeper into each of these components.
Window is an abstract class.
The concrete implementation of window is foreign window.
As we could see, one window extends the window, plus the foreign window class basically manages the
views.
We'll see that later in this section.
Window manager, as we could see, is an interface class that inherits from The View manager.
As the name says, it's used to manage the windows its implementation classes.
Window Manager.
MPL Window Manager.
MPL implements window manager.
If you want to add and delete windows, we can use window manager.
But this is instructed or handled by WMS or Window Manager Service.
That's why we call Window Manager Service as the boss of the window management system in Android.
We know manager and GMs communicate across processes through Binder as a system service window manager
service has many APIs that are not exposed to window manager.
The relationship between Window Window Manager and WMR or Window Management Service can be briefly represented
by the following figure.
As you can see from this figure, window contains view and manager's view.
Window is represented by a dotted line because a window is an abstract concept and it's not real.
And the entity of window is actually the view.
Window manager is used to manage window and the functions provided by Window Manager will eventually
be handled by the WMR or Window Management Service.
Now let's analyze window manager in detail.
Window manager, as we know, is an interface which inherits View Manager.
View Manager is an interface which defines three methods add view, update, view, layout and remote
view.
These are used to add update and delete views.
Window Manager also inherits these methods and the parameters passed in by these methods are views.
So the parameters past within all these functions are views.
Right?
This shows that window manager manages window in the form of views while inheriting Window Manager.
Window manager also adds many functions and constants related to the type and level of windows.
It also adds inner classes and methods.
So in short window manager inherits view manager and it inherits the three methods defined within view
manager.
In addition to that, it adds many constants, methods and inner classes within Window Manager.
Window is an abstract class and its concrete implementation is for window.
The form window extends window and implements a lot of methods and constants.
The foreign window is created during the activity startup process.
So during the activity startup process from launch activity method from activity thread is triggered.
And within this method activity dot attach method is called within the activity dot attach method.
We could see that the form window object is getting created and if we come further down the set window
manager method is called and within set window manager it checks if the volume the window manager object
is null.
Then it calls the get system service method.
So get system service method is called by using the context object and the MPL object or the implementation
of context is in context.
I am so within context.
I feel we have get system service implemented.
So in the get system service method, we could see that it's calling the system service registry dot
get system service method and passing in the name of the service.
Let's go to System Service Registry.
So here we can see the first object is the context itself and then the name.
So within the System Service Registry, we could see that it gets the service object from this system
service features.
So this is basically a map and here we have the system service names stored within a map and let's see
how this map is getting loaded.
So what to expect when we pass the window service.
So to understand that, we have to look at system service, registry register, system service.
So within that register system service, within this method, we could see that the create service method
is override and it returns the window manager ample.
So when the window manager I am Bill as we know, is the implementation of the window manager.
So it's pretty evident that that the set window manager method will get a window manager ample object.
And here we could see that window manager is set as the window manager, a MPL object which we got from
here.
So this will return a window manager imp object.
And with this it calls the create local window manager and the window manager is initialized here.
So this will be the parent window.
So within this parent window will be adding the views and that is done by using Ad View's method.
So we'll dig deeper into add views in a later tutorial.
But in this tutorial, what you need to understand is within the window manager employed ad view method,
we are calling the ad view from M Global.
So what exactly is M global?
So we could see that window manager employed basically doesn't add the view on itself.
It uses m global object.
So what exactly is M global?
So M global is an object of window manager global class.
Let's go to Window Manager Global Class so we could see that.
Window Manager Global class is basically a singleton class.
So we create the instance of window manager global by calling the gate instance and it always returns
a single instance as default window manager.
So to summarize, it can be seen that the window manager global is a singleton, so indicating that
there will be only one instance of window manager global in a process.
So here is a relationship diagram between window and window manager.
So as we could see, the form window inherits from window and window is associated with window manager
through the set window manager method window manager inherits from the interface view manager and the
Window Manager.
MPL is the implementation class of window manager interface, but the specific implementations are delegated
to the Window Manager global implementation, which is basically a singleton class.