What is an Android window?
Asked Answered
C

4

88

What is a Window in Android?

I thought the top-most level in Android is called Activity, which is the screen you see.

Can someone tell me what a Window in Android is? do we just have one or multiple of them.

Confucius answered 26/2, 2012 at 8:52 Comment(0)
F
13

The Activity is what you would call a Window.

Technically speaking, the Activity creates the Window for you.

You can have many of them, but normally not synchronously. To ask for additional information you can call a Dialog, or fire an Intent to another Activity.

For more information visit this link.

Factitious answered 26/2, 2012 at 9:14 Comment(3)
There is activity.getWindow(), so window is a part of Activity.Hypogene
Thank you Knossos, for this informative and simple answer.Consumption
Thank you also Zon for this activity property.Consumption
F
197

[UPDATE] (Let me share what I've learned about Window after original answer)

In one sentence, A Window is a rectangular area which has one view hierarchy. Colored rectangles in below image are windows.

enter image description here

As you can see, there can be multiple windows in one screen, and WindowManager manages them. Window list in current screen can be obtained via Hierarchy Viewer, or adb shell dumpsys window.

Window list in Hierarchy Viewer example : enter image description here

(Below is original answer)


I had the same question, and I hope this could help you guys.

According to Android Developer Documentation,

"Each activity is given a window in which to draw its user interface."

and, Dianne Hackborn, who is a Android framework engineer, gave some definitions here. She said,

A window is basically like you think of a window on the desktop. It has a single Surface in which the contents of the window is rendered. An application interacts with the Window Manager to create windows; the Window Manager creates a Surface for each window and gives it to the application for drawing. The application can draw whatever it wants in the Surface; to the Window Manager it is just an opaque rectangle.

A Surface is an object holding pixels that are being composited to the screen. Every window you see on the screen (a dialog, your full-screen activity, the status bar) has its own surface that it draws in to, and Surface Flinger renders these to the final display in their correct Z-order. A surface typically has more than one buffer (usually two) to do double-buffered rendering: the application can be drawing its next UI state while the surface flinger is compositing the screen using the last buffer, without needing to wait for the application to finish drawing.

A View is an interactive UI element inside of a window. A window has a single view hierarchy attached to it, which provides all of the behavior of the window. Whenever the window needs to be redrawn (such as because a view has invalidated itself), this is done into the window's Surface. The Surface is locked, which returns a Canvas that can be used to draw into it. A draw traversal is done down the hierarchy, handing the Canvas down for each view to draw its part of the UI. Once done, the Surface is unlocked and posted so that the just drawn buffer is swapped to the foreground to then be composited to the screen by Surface Flinger.

Also, I found some other info from Romain Guy's presentation(You can watch his talk at San Francisco Android user group from here, and download full slides from here)

enter image description here

So, in a nutshell:

  • An Activity has a window (in which it draws its user interface),
  • a Window has a single Surface and a single view hierarchy attached to it,
  • a Surface include ViewGroup which holds views.
Freeze answered 7/5, 2013 at 9:54 Comment(3)
Thanks for the brilliant answer and links. Can someone please tell me where does the decorView fit in, in this explanation?Celina
Can you tell me why does view.getLocationInWindow() returns y coordinate such that it contains the status bar height too. Status bar is supposed to be in another window. Also, I have checked that the window I am talking about is an activity window.Isomorphism
Depending on your activity's theme, system ui flags, etc., it may sit below the status bar (so that the status bar's height isn't included in the window) or it may sit behind the status bar (so that your activity can draw behind a transparent status bar, in which case the status bar height is included in the window). In particular, if you're using a custom status bar color, then you're drawing behind the status bar.Omnivore
D
37

I'd like to say in brief:

Application --->
  Activity --->
    Window Manager --->
      Window --->
        Surface ---> 
          Canvas --->
            View Root ---> 
              View Group --->
                View ---> 
                  Bitmap/Open GL panel ---> 
                    Current Surface Buffer ---> 
                      Surface Flinger --->
                        Screen
Dedradedric answered 15/11, 2017 at 5:18 Comment(1)
Thanks dear Finwe for this better formatting.Frankly,I'm entirely new to stackoverflow.Dedradedric
I
22

Android: Window, Surface, Canvas, and Bitmap Here is a very basic and simple conceptual overview of how interaction happens among the Window, Surface, Canvas, and Bitmap.

Intertidal answered 21/7, 2016 at 6:49 Comment(2)
Correspond the upper and lower Surfaces in the diagram with the status and navigation bar?Shayneshays
Every window on the screen has a surface. There can be multiple windows on screen. Yes, navigation and status bars have their associated windows and attached surfaces. The above picture is just a sample illustration of the concept.Intertidal
F
13

The Activity is what you would call a Window.

Technically speaking, the Activity creates the Window for you.

You can have many of them, but normally not synchronously. To ask for additional information you can call a Dialog, or fire an Intent to another Activity.

For more information visit this link.

Factitious answered 26/2, 2012 at 9:14 Comment(3)
There is activity.getWindow(), so window is a part of Activity.Hypogene
Thank you Knossos, for this informative and simple answer.Consumption
Thank you also Zon for this activity property.Consumption

© 2022 - 2024 — McMap. All rights reserved.