# SurfaceHolder.Callback

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Callback

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/view/SurfaceHolder.Callback "View this page in Java")  

```
interface Callback
```

|----------------------------------------------------------------------------------------------------------------------------|
| [android.view.SurfaceHolder.Callback](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#) |

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Direct Subclasses [SurfaceHolder.Callback2](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2) |----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------| | [SurfaceHolder.Callback2](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2) | Additional callbacks that can be received for[Callback](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#). | |

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Indirect Subclasses [GLSurfaceView](https://developer.android.com/reference/kotlin/android/opengl/GLSurfaceView.html#),[NativeActivity](https://developer.android.com/reference/kotlin/android/app/NativeActivity.html#) |----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | [GLSurfaceView](https://developer.android.com/reference/kotlin/android/opengl/GLSurfaceView.html#) | An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering. | | [NativeActivity](https://developer.android.com/reference/kotlin/android/app/NativeActivity.html#)  | Convenience for implementing an activity that will be implemented purely in native code.          | |

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

## Summary

|                                                                                                                                                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                                                                                                                                                              ||
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [surfaceChanged](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int))`(`holder:` `[SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder)`, `format:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `width:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `height:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` This is called immediately after any structural changes (format or size) have been made to the surface. |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [surfaceCreated](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder))`(`holder:` `[SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder)`)` This is called immediately after the surface is first created.                                                                                                                                                                                                                                                                                                                                                           |
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [surfaceDestroyed](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder))`(`holder:` `[SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder)`)` This is called immediately before a surface is being destroyed.                                                                                                                                                                                                                                                                                                                                                      |

## Public methods

### surfaceChanged

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#surfaceCreated(android.view.SurfaceHolder)).

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `holder` | [SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder):The SurfaceHolder whose surface has changed. This value cannot be`null`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `format` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new[PixelFormat](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#)of the surface. Value is[android.graphics.PixelFormat#RGBA_8888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_8888:kotlin.Int),[android.graphics.PixelFormat#RGBX_8888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBX_8888:kotlin.Int),[android.graphics.PixelFormat#RGBA_F16](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_F16:kotlin.Int),[android.graphics.PixelFormat#RGBA_1010102](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGBA_1010102:kotlin.Int),[android.graphics.PixelFormat#RGB_888](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_888:kotlin.Int),[android.graphics.PixelFormat#RGB_565](https://developer.android.com/reference/kotlin/android/graphics/PixelFormat.html#RGB_565:kotlin.Int), or android.graphics.PixelFormat.R_8 |
| `width`  | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new width of the surface. Value is 0 or greater                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `height` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):The new height of the surface. Value is 0 or greater                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

### surfaceCreated

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/view/Surface), so you should not draw into the Surface here if your normal rendering will be in another thread.

|                                                                                     Parameters                                                                                     ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `holder` | [SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder):The SurfaceHolder whose surface is being created. This value cannot be`null`. |

### surfaceDestroyed

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder):The SurfaceHolder whose surface is being destroyed. This value cannot be`null`. |