# SurfaceHolder.Callback2

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

# Callback2

*** ** * ** ***

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

```
interface Callback2 : SurfaceHolder.Callback
```

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

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known Direct 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.          | |

Additional callbacks that can be received for[Callback](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback).

## Summary

|                                                                                                                                                                                                                                                                                               Public methods                                                                                                                                                                                                                                                                                               ||
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| abstract[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [surfaceRedrawNeeded](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2#surfaceRedrawNeeded(android.view.SurfaceHolder))`(`holder:` `[SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder)`)` Called when the application needs to redraw the content of its surface, after it is resized or for some other reason.                                                                                                                           |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)     | [surfaceRedrawNeededAsync](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2#surfaceRedrawNeededAsync(android.view.SurfaceHolder,%20java.lang.Runnable))`(`holder:` `[SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder)`, `drawingFinished:` `[Runnable](https://developer.android.com/reference/kotlin/java/lang/Runnable.html#)`)` An alternative to surfaceRedrawNeeded where it is not required to block until the redraw is complete. |

| Inherited functions ||
|---|---|
| From class[Callback](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback) |------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [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)`)` <br /> 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)). <br /> | | [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)`)` <br /> 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. <br />                                                                                                                                                                                                                                                                                                             | | [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)`)` <br /> 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. <br />                                                                                                                                                                                                                                                                                                                                                             | ||

## Public methods

### surfaceRedrawNeeded

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

```
abstract fun surfaceRedrawNeeded(holder: SurfaceHolder): Unit
```

Called when the application needs to redraw the content of its surface, after it is resized or for some other reason. By not returning from here until the redraw is complete, you can ensure that the user will not see your surface in a bad state (at its new size before it has been correctly drawn that way). This will typically be preceeded by a call to[surfaceChanged](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder,%20kotlin.Int,%20kotlin.Int,%20kotlin.Int)). As of O,[surfaceRedrawNeededAsync](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2#surfaceRedrawNeededAsync(android.view.SurfaceHolder,%20java.lang.Runnable))may be implemented to provide a non-blocking implementation. If[surfaceRedrawNeededAsync](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2#surfaceRedrawNeededAsync(android.view.SurfaceHolder,%20java.lang.Runnable))is not implemented, then this will be called instead.

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

### surfaceRedrawNeededAsync

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

```
open fun surfaceRedrawNeededAsync(
    holder: SurfaceHolder, 
    drawingFinished: Runnable
): Unit
```

An alternative to surfaceRedrawNeeded where it is not required to block until the redraw is complete. You should initiate the redraw, and return, later invoking drawingFinished when your redraw is complete. This can be useful to avoid blocking your main application thread on rendering. As of O, if this is implemented[surfaceRedrawNeeded](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2#surfaceRedrawNeeded(android.view.SurfaceHolder))will not be called. However it is still recommended to implement[surfaceRedrawNeeded](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder.Callback2#surfaceRedrawNeeded(android.view.SurfaceHolder))for compatibility with older versions of the platform.

|                                                                                                Parameters                                                                                                ||
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `holder`          | [SurfaceHolder](https://developer.android.com/reference/kotlin/android/view/SurfaceHolder):The SurfaceHolder which needs redrawing. This value cannot be`null`.                       |
| `drawingFinished` | [Runnable](https://developer.android.com/reference/kotlin/java/lang/Runnable.html#):A runnable to signal completion. This may be invoked from any thread. This value cannot be`null`. |