Package io.flutter.view

# Interface TextureRegistry.SurfaceProducer.Callback

Enclosing interface:
  TextureRegistry.SurfaceProducer

public static interface TextureRegistry.SurfaceProducer.Callback
Callback invoked by `TextureRegistry.SurfaceProducer.setCallback(Callback)`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default void`
  `onSurfaceAvailable()`
  Invoked when an Android application is resumed after `onSurfaceDestroyed()`.
  `default void`
  `onSurfaceCreated()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Override and use `onSurfaceAvailable()` instead.
  `void`
  `onSurfaceDestroyed()`
  Invoked when a `Surface` returned by `TextureRegistry.SurfaceProducer.getSurface()` is invalid.

- ## Method Details

  - ### onSurfaceCreated

    @Deprecated(since="Flutter 3.27", forRemoval=true) default void onSurfaceCreated()
    Deprecated, for removal: This API element is subject to removal in a future version.
    Override and use `onSurfaceAvailable()` instead.
    An alias for `onSurfaceAvailable()` with a less accurate name.

  - ### onSurfaceAvailable

    default void onSurfaceAvailable()
    Invoked when an Android application is resumed after `onSurfaceDestroyed()`.

    Applications should now call `TextureRegistry.SurfaceProducer.getSurface()` to get a new `Surface`, as the previous one was destroyed and released as a result of a low memory event from the Android OS.

         void example(SurfaceProducer producer) {
           producer.setCallback(new SurfaceProducer.Callback() {
             @override
             public void onSurfaceAvailable() {
               Surface surface = producer.getSurface();
               redrawOrUse(surface);
             }

             // ...
           });
         }

  - ### onSurfaceDestroyed

    void onSurfaceDestroyed()
    Invoked when a `Surface` returned by `TextureRegistry.SurfaceProducer.getSurface()` is invalid.

    In a low memory environment, the Android OS will signal to Flutter to release resources, such as surfaces, that are not currently in use, such as when the application is in the background, and this method is subsequently called to notify a plugin author to stop using or rendering to the last surface.

    Use `onSurfaceAvailable()` to be notified to resume rendering.

         void example(SurfaceProducer producer) {
           producer.setCallback(new SurfaceProducer.Callback() {
             @override
             public void onSurfaceDestroyed() {
               // Store information about the last frame, if necessary.
               // Potentially release other dependent resources.
             }

             // ...
           });
         }