Recently came into contact with the Surfaceview,surfaceholder,surfaceholder.callback, has not begged for its solution, now to superficial understanding of them.
Let's take a look at the official definition:
1.SurfaceView
Surfaceview is the inheritance class for view, which has a built-in surface for drawing. You can control the format and size of this surface. Surfaceview controls where this surface is drawn.
Surface is a deep sort (z-ordered), which indicates that it is always behind its own window. The Surfaceview provides a visible area that is visible only on the surface portion of the visible area and not visible outside the visible area. The layout display of surface is affected by the view hierarchy, and its sibling view nodes are displayed at the top. This means that the content of surface is obscured by its sibling view, which can be used to place a cloak (overlays) (for example, text and buttons). Note that if you have transparent controls on your surface, each change will cause the framework to recalculate the transparency of its and top-level controls, which can affect performance.
You can access this surface through the Surfaceholder interface. This interface can be obtained using the Getholder () method.
Surface is created when Surfaceview becomes visible, and surface is destroyed before Surfaceview is hidden. This will save resources. If you want to see when your surface is created and destroyed, you can reload surfacecreated (Surfaceholder) and surfacedestroyed (Surfaceholder).
The core of Surfaceview is the provision of two threads: the UI thread and the render thread. It should be noted here:
1> all methods of Surfaceview and Surfaceholder.callback should be called in the UI thread, which is generally the main thread of the application. The various variables to be accessed by the render thread should be processed synchronously.
2> because surface may be destroyed, it is only in SurfaceHolder.Callback.surfaceCreated () and SurfaceHolder.Callback.surfaceDestroyed () is valid, so make sure that the rendering thread accesses legitimate, valid surface.
2.SurfaceHolder
Displays an abstract interface to your surface, allowing you to control the size and formatting of your surface, edit pixels on your surface, and monitor surace changes. This interface is typically implemented through the Surfaceview class.
3. Surfaceholder.callback
Users can implement this interface to receive messages for surface changes. When used in a surfaceview, it is only valid between SurfaceHolder.Callback.surfaceCreated () and SurfaceHolder.Callback.surfaceDestroyed (). The way to set callback is Surfaceholder.addcallback.
After reading the official introduction, understand a lot, surfaceview with Z-order, but also in the above operation like Wood has, there are separate rendering thread Oh pro. If you do game development, of course, choose Surfaceview.
Android Big Literacy Surfaceview,surfaceholder,surfaceholder.callback