You need to understand a few things before
On Android each Activity has one ViewRoot and usually one Window attached to it. However, SurfaceView has its own window. So, if an Activity has a SurfaceView , it will have more than one window.
This operation is used to display a screen that occupies the entire window. Views are attached to this window. Each window has a surface, and the surface uses Canvas to draw on the surface. The window to which the view is attached belongs to the surface.
Basically, ViewRoot is responsible for collecting and sending input, and View is responsible for managing focus / key events, Canvas is only responsible for the drawing operation using onDraw() .
setContentView(View) is a method available only to Activity . Inside, it calls setContentView(View) Window . This method sets the contents of an activity to an explicit representation. This view is placed directly in the hierarchy of activities. Calling this function “blocks” various characteristics of the window that cannot be changed from this point forward. Therefore, it is called only once.
LayoutInflater used to instantiate an XML file into the corresponding View objects. Basically the goal is to create view objects at runtime depending on the requirement. The best example is AdapterViews , like ListView , Spinner , etc., where at runtime a separate view object is created corresponding to a single record, depending on the number of records.
In the case of Toast , a LayoutInflater used if the child’s representation is changed dynamically, for example. changing the image at runtime. If no changes are required in the child views, just setView(View) from the toast is enough to set the layout for the toast.
Same as Toast with AlertDialog if you are closely watching.
Hope this helps you.