Here is some definitions:
A Surface is an object holding pixels that's being composited to the screen. Every window you see on the screen (a dialog, your full-screen activity, the status bar) have 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 have more than one buffer (usually-A-double-buffered rendering:the application can be drawing The IT next UI state and the surface Flinger is compositing the screens using the last buffer, without needing to wait for The application to finish drawing.
-
A window is basically like you think for A window on the desktop. It has a single Surface in which the contents of the Windows 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's just an opaque rectangle.
-
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 have invalidated itself), this was done into the window ' s Su Rface. The Surface is locked, which returns a Canvas that can was used to draw into it. A draw traversal is do down the the hierarchy, handing the Canvas under for each view to draw its part of the UI. Once done, the Surface was unlocked and posted so, the just drawn buffer was swapped to the foreground to then being compos Ited to the screens by Surface Flinger.
-
A surfaceview is a special implementation of View that also creates it own dedicated Surface for the application To directly draw into (outside of the normal view hierarchy, which otherwise must share the single Surface for the window ). The ' This works ' is simpler than expect--all surfaceview does are ask the window manager to create a new window , telling it to z-order. window either immediately behind or in front of the Surfaceview ' s window, and positioning it To match where the Surfaceview appears in the containing window. If the surface is a being placed behind the main window (in Z order), Surfaceview also fills it part of the main window wit H transparency So, the surface can be seen.
A Bitmap is just the interface to some pixel data. The pixels may is allocated by BITMAP itself if you're directly creating one, or it may be pointing to pixels it doesn ' T own such as what internally happens to hooks a Canvas up to a Surface for drawing. (A Bitmap is created and pointed to the current drawing buffer of the Surface.)
Also keep in mind so, as this implies, a surfaceview is a pretty heavy-weight object. If you had multiple surfaceviews in a particular UI, the stop and think about whether the is really needed. If you had more than than, you almost certainly had too many.
Understanding Canvas and Surface Concepts