Added in API level 1

Callback


interface Callback
android.view.SurfaceHolder.Callback

A client may implement this interface to receive information about changes to the surface. When used with a SurfaceView, the Surface being held is only available between calls to surfaceCreated(android.view.SurfaceHolder) and surfaceDestroyed(android.view.SurfaceHolder). The Callback is set with SurfaceHolder.addCallback method.

Summary

Public methods
abstract Unit
surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int)

This is called immediately after any structural changes (format or size) have been made to the surface.

abstract Unit

This is called immediately after the surface is first created.

abstract Unit

This is called immediately before a surface is being destroyed.

Public methods

surfaceChanged

Added in API level 1
abstract fun surfaceChanged(
    holder: SurfaceHolder,
    format: Int,
    width: Int,
    height: Int
): Unit

This is called immediately after any structural changes (format or size) have been made to the surface. You should at this point update the imagery in the surface. This method is always called at least once, after surfaceCreated.

Parameters
holder SurfaceHolder: The SurfaceHolder whose surface has changed. This value cannot be null.
format Int: The new PixelFormat of the surface. Value is android.graphics.PixelFormat#RGBA_8888, android.graphics.PixelFormat#RGBX_8888, android.graphics.PixelFormat#RGBA_F16, android.graphics.PixelFormat#RGBA_1010102, android.graphics.PixelFormat#RGB_888, android.graphics.PixelFormat#RGB_565, or android.graphics.PixelFormat.R_8
width Int: The new width of the surface. Value is 0 or greater
height Int: The new height of the surface. Value is 0 or greater

surfaceCreated

Added in API level 1
abstract fun surfaceCreated(holder: SurfaceHolder): Unit

This is called immediately after the surface is first created. Implementations of this should start up whatever rendering code they desire. Note that only one thread can ever draw into a Surface, so you should not draw into the Surface here if your normal rendering will be in another thread.

Parameters
holder SurfaceHolder: The SurfaceHolder whose surface is being created. This value cannot be null.

surfaceDestroyed

Added in API level 1
abstract fun surfaceDestroyed(holder: SurfaceHolder): Unit

This is called immediately before a surface is being destroyed. After returning from this call, you should no longer try to access this surface. If you have a rendering thread that directly accesses the surface, you must ensure that thread is no longer touching the Surface before returning from this function.

Parameters
holder SurfaceHolder: The SurfaceHolder whose surface is being destroyed. This value cannot be null.