io.flutter.embedding.engine.systemchannels

## Class RestorationChannel

- java.lang.Object
- - io.flutter.embedding.engine.systemchannels.RestorationChannel

-     public class RestorationChannel
      extends Object

  System channel to exchange restoration data between framework and engine.

  The engine can obtain the current restoration data from the framework via this channel to store it on disk and - when the app is relaunched - provide the stored data back to the framework to recreate the original state of the app.

  The channel can be configured to delay responding to the framework's request for restoration data via `waitForRestorationData` until the engine-side has provided the data. This is useful when the engine is pre-warmed at a point in the application's life cycle where the restoration data is not available yet. For example, if the engine is pre-warmed as part of the Application before an Activity is created, this flag should be set to true because Android will only provide the restoration data to the Activity during the onCreate callback.

  The current restoration data provided by the framework can be read via `getRestorationData()`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `boolean` | `waitForRestorationData` Whether the channel delays responding to the framework's initial request for restoration data until `setRestorationData` has been called.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RestorationChannel(DartExecutor dartExecutor, boolean waitForRestorationData)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearData()` Clears the current restoration data.
    `byte[]` | `getRestorationData()` Obtain the most current restoration data that the framework has provided.
    `void` | `setRestorationData(byte[] data)` Set the restoration data from which the framework will restore its state.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### waitForRestorationData

          public final boolean waitForRestorationData

      Whether the channel delays responding to the framework's initial request for restoration data until `setRestorationData` has been called.

      If the engine never calls `setRestorationData` this flag must be set to false. If set to true, the engine must call `setRestorationData` either with the actual restoration data as argument or null if it turns out that there is no restoration data.

      If the response to the framework's request for restoration data is not delayed until the data has been set via `setRestorationData`, the framework may intermittently initialize itself to default values until the restoration data has been made available. Setting this flag to true avoids that extra work.

  - ### Constructor Detail

    - #### RestorationChannel

          public RestorationChannel(@NonNull
                                    DartExecutor dartExecutor,
                                    @NonNull
                                    boolean waitForRestorationData)

  - ### Method Detail

    - #### getRestorationData

          public byte[] getRestorationData()

      Obtain the most current restoration data that the framework has provided.

    - #### setRestorationData

          public void setRestorationData(byte[] data)

      Set the restoration data from which the framework will restore its state.

    - #### clearData

          public void clearData()

      Clears the current restoration data.

      This should be called just prior to a hot restart. Otherwise, after the hot restart the state prior to the hot restart will get restored.